rust_decimal/
lib.rs

1#![doc = include_str!(concat!(env!("OUT_DIR"), "/README-lib.md"))]
2#![forbid(unsafe_code)]
3#![deny(clippy::print_stdout, clippy::print_stderr)]
4#![cfg_attr(not(feature = "std"), no_std)]
5#![cfg_attr(docsrs, feature(doc_auto_cfg))]
6extern crate alloc;
7
8mod constants;
9mod decimal;
10mod error;
11mod ops;
12pub mod str;
13
14// We purposely place this here for documentation ordering
15mod arithmetic_impls;
16
17#[cfg(feature = "rust-fuzz")]
18mod fuzz;
19#[cfg(feature = "maths")]
20mod maths;
21#[cfg(feature = "db-diesel-mysql")]
22mod mysql;
23#[cfg(any(
24    feature = "db-tokio-postgres",
25    feature = "db-postgres",
26    feature = "db-diesel-postgres",
27))]
28mod postgres;
29#[cfg(feature = "proptest")]
30mod proptest;
31#[cfg(feature = "rand")]
32mod rand;
33#[cfg(feature = "rand-0_9")]
34mod rand_0_9;
35#[cfg(feature = "rocket-traits")]
36mod rocket;
37#[cfg(all(
38    feature = "serde",
39    not(any(
40        feature = "serde-with-str",
41        feature = "serde-with-float",
42        feature = "serde-with-arbitrary-precision"
43    ))
44))]
45mod serde;
46/// Serde specific functionality to customize how a decimal is serialized/deserialized (`serde_with`)
47#[cfg(all(
48    feature = "serde",
49    any(
50        feature = "serde-with-str",
51        feature = "serde-with-float",
52        feature = "serde-with-arbitrary-precision"
53    )
54))]
55pub mod serde;
56
57pub use decimal::{Decimal, RoundingStrategy};
58pub use error::Error;
59#[cfg(feature = "maths")]
60pub use maths::MathematicalOps;
61
62/// A convenience module appropriate for glob imports (`use rust_decimal::prelude::*;`).
63pub mod prelude {
64    #[cfg(feature = "macros")]
65    pub use super::dec;
66    #[cfg(feature = "maths")]
67    pub use crate::maths::MathematicalOps;
68    pub use crate::{Decimal, RoundingStrategy};
69    pub use core::str::FromStr;
70    pub use num_traits::{FromPrimitive, One, Signed, ToPrimitive, Zero};
71}
72
73#[cfg(feature = "macros")]
74pub use rust_decimal_macros::dec;
75
76#[cfg(feature = "diesel")]
77extern crate diesel;
78
79/// Shortcut for `core::result::Result<T, rust_decimal::Error>`. Useful to distinguish
80/// between `rust_decimal` and `std` types.
81pub type Result<T> = core::result::Result<T, Error>;
82
83// #[cfg(feature = "legacy-ops")]
84// compiler_error!("legacy-ops has been removed as 1.x");