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::MoneyParser;
20    pub use crate::PercentOps;
21    pub use crate::RoundingStrategy;
22    pub use crate::base::{Amount, DecimalNumber};
23    pub use crate::{Decimal, Money, MoneyError};
24
25    pub use crate::iso;
26
27    pub use crate::macros::{dec, money};
28
29    #[cfg(feature = "raw_money")]
30    pub use crate::RawMoney;
31    #[cfg(feature = "raw_money")]
32    pub use crate::macros::raw;
33
34    #[cfg(feature = "exchange")]
35    pub use crate::exchange::{Exchange, ExchangeRates, ObjRate, Rate};
36
37    #[cfg(feature = "obj_money")]
38    pub use crate::obj_money::*;
39
40    #[cfg(feature = "serde")]
41    pub use crate::serde;
42}
43
44// ------------------ MoneyOps contains all ops traits for money instance ------------------
45
46#[cfg(not(feature = "exchange"))]
47/// MoneyOps\<C\> trait contains all traits on money instance.
48pub trait MoneyOps<C>: BaseOps<C> + MoneyFormatter<C> + MoneyParser<C> + PercentOps<C>
49where
50    C: Currency,
51{
52}
53
54#[cfg(feature = "exchange")]
55/// MoneyOps\<C\> trait contains all traits on money instance.
56pub trait MoneyOps<C>:
57    BaseOps<C> + MoneyFormatter<C> + MoneyParser<C> + PercentOps<C> + Exchange<C>
58where
59    C: Currency,
60{
61}
62
63// -----------------------------------------------------------------------------------------
64
65pub use rust_decimal::Decimal;
66
67/// Contains helper macros.
68pub mod macros;
69
70mod base;
71pub use base::{BaseMoney, BaseOps, IterOps, MoneyFormatter, MoneyParser, RoundingStrategy};
72
73mod error;
74pub use error::MoneyError;
75
76pub use currencylib::Currency;
77
78/// Contains all ISO 4217 currencies.
79pub mod iso {
80    pub use currencylib::*;
81}
82
83mod money;
84pub use money::Money;
85
86#[cfg(feature = "raw_money")]
87mod raw_money;
88#[cfg(feature = "raw_money")]
89pub use raw_money::RawMoney;
90
91mod iter_ops;
92mod ops;
93mod percent_ops;
94pub use percent_ops::PercentOps;
95mod split_alloc_ops;
96
97#[cfg(feature = "exchange")]
98mod exchange;
99#[cfg(feature = "exchange")]
100pub use exchange::{Exchange, ExchangeRates};
101
102#[cfg(feature = "serde")]
103/// Serde implementations
104pub mod serde;
105
106mod fmt;
107
108mod parse;
109
110#[cfg(feature = "obj_money")]
111pub mod obj_money;
112
113// ----------------- test modules -----------------
114
115#[cfg(test)]
116mod fmt_test;
117
118#[cfg(test)]
119mod money_test;
120
121#[cfg(test)]
122mod error_test;
123
124#[cfg(test)]
125mod ops_test;
126
127#[cfg(test)]
128mod iter_ops_test;
129
130#[cfg(test)]
131mod percent_ops_test;
132
133#[cfg(test)]
134mod split_alloc_ops_test;
135
136#[cfg(all(test, feature = "exchange"))]
137mod exchange_test;