1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
pub use Dec;
pub use ParseDecError;
/// Builds a [`Dec`] from a decimal literal at compile time.
///
/// The tokens are stringified and handed to [`Dec::parse_const`] inside a
/// `const` block, so the value is a constant and a malformed literal fails the
/// build instead of the trade. The literal accepts everything
/// [`FromStr`](std::str::FromStr) does: a sign, an exponent, `_` separators,
/// and more than [`Dec::SCALE`] decimal places, where the excess rounds half
/// away from zero.
///
/// ```
/// use troy::{Dec, dec};
///
/// const TICK: Dec = dec!(0.01);
/// assert_eq!(dec!(104_237.25) + TICK, dec!(104_237.26));
/// assert_eq!(dec!(-1.5e3), dec!(-1500));
/// assert_eq!(dec!(0.0000000000000000005), Dec::EPSILON);
/// ```
///
/// A literal that does not parse, or one outside the finite range, is rejected
/// by the compiler:
///
/// ```compile_fail
/// # use troy::dec;
/// let price = dec!(banana);
/// ```