custom_dimensions/
custom_dimensions.rs1use shrewnit::prelude::*;
2
3shrewnit::dimension!(
4 Current {
5 canonical: Amperes,
6
7 Amperes: 1.0 per canonical,
8 } where {
9 Self * Voltage => Power in Watts,
10 }
11);
12
13shrewnit::dimension!(
14 Voltage {
15 canonical: Volts,
16
17 Volts: 1.0 per canonical,
18 } where {
19 Self * Current => Power in Watts,
20 }
21);
22
23shrewnit::dimension!(
24 Power {
25 canonical: Watts,
26
27 Watts: 1.0 per canonical,
28 } where {
29 Self / Voltage => Current in Amperes,
30 Self / Current => Voltage in Volts,
31 }
32);
33
34fn main() {
35 let current = Amperes * 5.0;
36 let voltage = Volts * 120.0;
37
38 let power: Power = current * voltage;
39
40 println!("{}", power.to::<Watts>())
41}