Skip to main content

moneylib/
lib.rs

1#![doc = include_str!("../README.md")]
2#![forbid(unsafe_code)]
3#![forbid(clippy::float_arithmetic)]
4#![forbid(clippy::float_cmp)]
5#![forbid(clippy::as_conversions)]
6#![forbid(clippy::cast_possible_truncation)]
7#![forbid(clippy::cast_sign_loss)]
8#![forbid(clippy::cast_possible_wrap)]
9#![forbid(clippy::unwrap_used)]
10
11/// Contains all types and traits of moneylib.
12pub mod prelude {
13    pub use crate::BaseMoney;
14    pub use crate::BaseOps;
15    pub use crate::Currency;
16    pub use crate::IterOps;
17    pub use crate::MoneyFormatter;
18    pub use crate::MoneyOps;
19    pub use crate::PercentOps;
20    pub use crate::RoundingStrategy;
21    pub use crate::{Decimal, Money, MoneyError};
22
23    pub use crate::iso;
24
25    pub use crate::macros::{dec, money};
26
27    #[cfg(feature = "raw_money")]
28    pub use crate::RawMoney;
29    #[cfg(feature = "raw_money")]
30    pub use crate::macros::raw;
31
32    #[cfg(feature = "exchange")]
33    pub use crate::exchange::{Exchange, ExchangeRates, ObjRate, Rate};
34
35    #[cfg(feature = "obj_money")]
36    pub use crate::ObjMoney;
37
38    #[cfg(feature = "serde")]
39    pub use crate::serde;
40}
41
42// ------------------ MoneyOps contains all ops traits for money instance ------------------
43
44#[cfg(not(feature = "exchange"))]
45/// MoneyOps\<C\> trait contains all traits on money instance.
46pub trait MoneyOps<C>: BaseOps<C> + MoneyFormatter<C> + PercentOps<C>
47where
48    C: Currency,
49{
50}
51
52#[cfg(feature = "exchange")]
53/// MoneyOps\<C\> trait contains all traits on money instance.
54pub trait MoneyOps<C>: BaseOps<C> + MoneyFormatter<C> + PercentOps<C> + Exchange<C>
55where
56    C: Currency,
57{
58}
59
60// -----------------------------------------------------------------------------------------
61
62pub use rust_decimal::Decimal;
63
64/// Contains helper macros.
65pub mod macros;
66
67mod base;
68pub use base::{BaseMoney, BaseOps, IterOps, MoneyFormatter, RoundingStrategy};
69
70mod error;
71pub use error::MoneyError;
72
73pub use currencylib::Currency;
74
75/// Contains all ISO 4217 currencies.
76pub mod iso {
77    pub use currencylib::*;
78}
79
80mod money;
81pub use money::Money;
82
83#[cfg(feature = "raw_money")]
84mod raw_money;
85#[cfg(feature = "raw_money")]
86pub use raw_money::RawMoney;
87
88mod dec_ops;
89mod iter_ops;
90mod ops;
91mod percent_ops;
92pub use percent_ops::PercentOps;
93mod split_alloc_ops;
94
95#[cfg(feature = "exchange")]
96mod exchange;
97#[cfg(feature = "exchange")]
98pub use exchange::{Exchange, ExchangeRates};
99
100#[cfg(feature = "serde")]
101/// Serde implementations
102pub mod serde;
103
104mod fmt;
105
106mod parse;
107
108#[cfg(feature = "obj_money")]
109mod obj_money;
110#[cfg(feature = "obj_money")]
111pub use obj_money::{ObjIterOps, ObjMoney};
112
113// ----------------- test modules -----------------
114
115#[cfg(test)]
116mod parse_test;
117
118#[cfg(test)]
119mod fmt_test;
120
121#[cfg(test)]
122mod money_test;
123
124#[cfg(test)]
125mod error_test;
126
127#[cfg(test)]
128mod ops_test;
129
130#[cfg(test)]
131mod iter_ops_test;
132
133#[cfg(test)]
134mod percent_ops_test;
135
136#[cfg(test)]
137mod split_alloc_ops_test;
138
139#[cfg(all(test, feature = "exchange"))]
140mod exchange_test;