Skip to content

Commit 0979799

Browse files
authored
[Docs] Includes macro information in published documentation (#716)
1 parent ffe9495 commit 0979799

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

.buildnumber

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
1
22
37
3-
0
3+
1

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ name = "rust_decimal"
1212
readme = "./README.md"
1313
repository = "https://github.com/paupino/rust-decimal"
1414
rust-version = "1.67.1"
15-
version = "1.37.0"
15+
version = "1.37.1"
1616

1717
[package.metadata.docs.rs]
1818
all-features = true

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ Alternatively, you can edit your `Cargo.toml` directly and run `cargo update`:
3232
rust_decimal = "1.37"
3333
```
3434

35+
To enable macro support, you can enable the `macros` feature:
36+
37+
```sh
38+
$ cargo add rust_decimal --features macros
39+
```
40+
3541
## Usage
3642

3743
Decimal numbers can be created in a few distinct ways. The easiest and most efficient method of creating a Decimal is to
@@ -106,6 +112,7 @@ assert_eq!(total, dec!(27.26));
106112
* [borsh](#borsh)
107113
* [c-repr](#c-repr)
108114
* [legacy-ops](#legacy-ops)
115+
* [macros](#macros)
109116
* [maths](#maths)
110117
* [ndarray](#ndarray)
111118
* [rkyv](#rkyv)
@@ -162,6 +169,21 @@ As of `1.10` the algorithms used to perform basic operations have changed which
162169
improvements.
163170
To maintain backwards compatibility this can be opted out of by enabling the `legacy-ops` feature.
164171

172+
### `macros`
173+
174+
The `macros` feature enables a compile time macro `dec` to be available at both the crate root, and via prelude.
175+
176+
This parses the input at compile time and converts it to an optimized `Decimal` representation. Invalid inputs will
177+
cause a compile time error.
178+
179+
Any Rust number format is supported, including scientific notation and alternate bases.
180+
181+
```rust
182+
use rust_decimal::prelude::*;
183+
184+
assert_eq!(dec!(1.23), Decimal::new(123, 2));
185+
```
186+
165187
### `maths`
166188

167189
The `maths` feature enables additional complex mathematical functions such as `pow`, `ln`, `enf`, `exp` etc.

macros/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ use syn::{
4242
parse_macro_input, Expr, Ident, LitInt, Result, Token,
4343
};
4444

45-
/// Transform a literal number directly to a `Decimal` at compile time. Any Rust number format works.
45+
/// Transform a literal number directly to a `Decimal` at compile time.
46+
///
47+
/// Any Rust number format works, for example:
4648
///
4749
/// - `dec!(1)`, `dec!(-1)`, `dec!(1_999)`, `dec!(- 1_999)`
4850
/// - `dec!(0b1)`, `dec!(-0b1_1111)`, `dec!(0o1)`, `dec!(-0o1_777)`, `dec!(0x1)`, `dec!(-0x1_Ffff)`
@@ -75,6 +77,8 @@ use syn::{
7577
/// assert_eq!("-5.4321", number.to_string());
7678
/// let number = dec!(-0o1_777);
7779
/// assert_eq!("-1023", number.to_string());
80+
/// let number = dec!(-1_777, radix 8);
81+
/// assert_eq!("-1023", number.to_string());
7882
/// ```
7983
///
8084
#[proc_macro]

0 commit comments

Comments
 (0)