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
use dimension_impl;
use *;
use Verify;
// To properly do this doctest, I probably need to document this in diman itself so I can use the
// dimension. Also, a surrounding module around dimension/unit_system is needed to make the doctest work
// due to the way it is compiled.
/// Create a system of units.
/// Usage:
/// ```rust ignore
/// #![allow(incomplete_features)]
/// #![feature(generic_const_exprs, adt_const_params)]
/// use diman::unit_system;
/// use diman::dimension;
///
/// #[dimension]
/// pub struct Dimension {
/// pub length: i32,
/// pub time: i32,
/// }
///
/// unit_system!(
/// Quantity,
/// Dimension,
/// [
/// def Length = { length: 1 },
/// def Time = { time: 1 },
/// def Velocity = Length / Time,
/// unit (meters, "m") = Length,
/// unit (kilometers, "km") = 1000.0 * meters,
/// unit (seconds, "s") = 1.0 * Time,
/// unit hours = 3600 * seconds,
/// unit meters_per_second = meters / seconds,
/// unit kilometers_per_hour = kilometers / hours,
/// constant MY_FAVORITE_VELOCITY = 1000 * meters_per_second,
/// ]
/// );
/// ```
/// Derives all required methods for a dimension type.
/// Only works on structs on which every field is `i32`.
/// Also adds derives of `PartialEq`, `Eq`, `Clone` and `Debug`.