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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//!
//! A collection of procedural macros for the beaumont crates.
//!
//! <div class="warning">This crate is in an early stage of development and
//! <strong>not</strong> production ready yet.<br>Use with caution!</div>
//!
use TokenStream;
use parse_macro_input;
// The inner implementation of the literal macro
/// Allow custom literals of `Decimal` numbers
///
/// Useful for creating decimal numbers the way you would normally create integer or floating
/// numbers, but appending the custom `d` suffix to the literal (instead of the `i32` or `f32`
/// usual suffixes). Also, useful for creating decimal numbers from string literals, still by appending the
/// custom `d` suffix instead of explicitly invoking a parser.
///
/// # Examples
/// ```ignore
/// use beaumont_numbers::Decimal;
/// use beaumont_macros::decimals;
///
/// #[allow_decimals]
/// fn do_something() {
/// // Create a decimal number from integer literals
/// let d1 = 12d;
///
/// // Create a decimal number from float literals
/// let d2 = 12.00d;
/// let d3 = -56712.3489d;
///
/// // Create a decimal number from string literals
/// let d4 = "190928.05"d;
/// }
/// ```
///
/// # Unhygienic
/// This macro is unhygienic, as it depends on the presence of the `Decimal` local name, referring
/// to any type for which an implementation of the `std::str::FromStr` trait exists.
/// While you can bring any `Decimal` you like, you're recommended to bring it as follows:
///
/// 1. either by using `beaumont_number::Decimal`,
/// 2. or by using `beaumont::Decimal` (which is a re-export of the same).
///
/// Create mathematical `Vector` from fixed-size array
///
/// # Unhygienic
/// This macro is unhygienic, as it depends on the presence of the `Vector` local name, referring
/// to any type for which an implementation of `core::convert::From<Box[A]>` trait exists.
/// While you can bring any `Vector` you wish, you're recommended to bring it as follows:
///
/// 1. either by using `beaumont_liner_algebra::Vector`,
/// 2. or by using `beaumont::Vector` (which is a re-export of the same).
///
/// Moreover, this macro can transform decimal literals (those ending with the `d` prefix)
/// without the need to annotate your functions with the `allow_decimals` macro.
///
/// # Examples
/// ```ignore
/// use beaumont_macros::vector;
/// use beaumont_numbers::Decimal;
/// use beaumont_linear_algebra::Vector;
///
/// let v: Vector<Decimal> = vector![1.0d, 2.0d, 3.0d];
/// assert_eq!(v.len(), 3);
/// ```