forked from iliekturtles/uom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
si.rs
54 lines (50 loc) · 1.48 KB
/
si.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
44
45
46
47
48
49
50
51
52
53
54
//! Example showing how to use the pre-built SI system.
extern crate uom;
use uom::si::f32::*;
use uom::si::length::{centimeter, kilometer, meter};
use uom::si::time::second;
use uom::si::velocity::{kilometer_per_second, meter_per_second};
use uom::si::Unit;
fn main() {
let l1 = Length::new::<meter>(15.0);
let l2 = Length::new::<centimeter>(10.0);
let t1 = Time::new::<second>(50.0);
let v1 = l1 / t1;
//let error = l1 + t1; // error[E0308]: mismatched types
println!(
"{:?} {} + {:?} {} = {:?} {}",
l1.get::<meter>(),
meter::abbreviation(),
l2.get::<centimeter>(),
centimeter::abbreviation(),
(l1 + l2).get::<meter>(),
meter::abbreviation()
);
println!(
"{:?} {} + {:?} {} = {:?} {}",
l1.get::<meter>(),
meter::abbreviation(),
l2.get::<centimeter>(),
centimeter::abbreviation(),
(l1 + l2).get::<kilometer>(),
kilometer::abbreviation()
);
println!(
"{:?} {} / {:?} {} = {:?} {}",
l1.get::<meter>(),
meter::abbreviation(),
t1.get::<second>(),
second::abbreviation(),
v1.get::<meter_per_second>(),
meter_per_second::abbreviation()
);
println!(
"{:?} {} / {:?} {} = {:?} {}",
l1.get::<meter>(),
meter::abbreviation(),
t1.get::<second>(),
second::abbreviation(),
v1.get::<kilometer_per_second>(),
kilometer_per_second::abbreviation()
);
}