-
Notifications
You must be signed in to change notification settings - Fork 5
/
units.rs
43 lines (37 loc) · 1.18 KB
/
units.rs
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
//! Define convenient units using the `si_scale` crate.
use si_scale::scale_fn;
// defines the `watts()` function: 18 W
scale_fn!(watts,
base: B1000,
constraint: UnitAndBelow,
mantissa_fmt: "{:.0}",
unit: "W",
doc: "Return a string with the value and its si-scaled unit of watts.");
// defines the `watts2()` function: 18.65 W
scale_fn!(watts2,
base: B1000,
constraint: UnitAndBelow,
mantissa_fmt: "{:.2}",
unit: "W",
doc: "Return a string with the value and its si-scaled unit of watts.");
// defines the `percent1()` function: 23.6 %
scale_fn!(percent1,
base: B1000,
constraint: UnitOnly,
mantissa_fmt: "{:.1}",
unit: "%",
doc: "Return a string with the value and its si-scaled percentage.");
// defines the `mhz()` function: 972 MHz
scale_fn!(mhz,
base: B1000,
constraint: UnitOnly,
mantissa_fmt: "{:.0}",
unit: "MHz",
doc: "Return a string with the value and its si-scaled unit of MHz.");
// defines the `bibytes1()` function: 9.56 GB
scale_fn!(bibytes1,
base: B1024,
constraint: UnitAndAbove,
mantissa_fmt: "{:.1}",
unit: "B",
doc: "Return a string with the value and its si-scaled unit of bibytes.");