@@ -22,44 +22,51 @@ Conversions to and from different units are simple, and operator overrides allow
22
22
- Temperature
23
23
- Weight
24
24
- Volume
25
+ - Pressure
25
26
26
27
### Examples
27
28
28
29
In your Cargo.toml add the dependency...
29
30
30
- ```
31
+ ``` toml
31
32
[dependencies ]
32
- measurements = "^0.2.1 "
33
+ measurements = " ^0.3.0 "
33
34
```
34
35
35
36
In your code...
36
37
37
38
``` rust
38
39
extern crate measurements;
39
40
40
- use measurements :: {Length , Temperature , Weight , Volume };
41
-
42
- // Lengths!
43
- let football_field = Length :: from_yards (100.0 );
44
- let meters = football_field . as_meters ();
45
- println! (" There are {} meters in a football field." , meters );
46
-
47
- /// Temperatures!
48
- let boiling_water = Temperature :: from_celsius (100.0 );
49
- let fahrenheit = boiling_water . as_fahrenheit ();
50
- println! (" Boiling water measures at {} degrees fahrenheit." , fahrenheit );
51
-
52
- // Weights!
53
- let metric_ton = Weight :: from_metric_tons (1.0 );
54
- let united_states_tons = metric_ton . as_short_tons ();
55
- let united_states_pounds = metric_ton . as_pounds ();
56
- println! (" One metric ton is {} U.S. tons - that's {} pounds!" , united_states_tons , united_states_pounds );
57
-
58
- // Volumes!
59
- let gallon = Volume :: from_gallons (1.0 );
60
- let pint = Volume :: from_pints (1.0 );
61
- let beers = gallon / pint ;
62
- println! (" A gallon of beer will pour {} pints!" , beers );
41
+ use measurements :: {Length , Pressure , Temperature , Volume , Weight };
42
+
43
+ fn main () {
44
+ // Lengths!
45
+ let football_field = Length :: from_yards (100.0 );
46
+ let meters = football_field . as_meters ();
47
+ println! (" There are {} meters in a football field." , meters );
48
+
49
+ /// Temperatures!
50
+ let boiling_water = Temperature :: from_celsius (100.0 );
51
+ let fahrenheit = boiling_water . as_fahrenheit ();
52
+ println! (" Boiling water measures at {} degrees fahrenheit." , fahrenheit );
53
+
54
+ // Weights!
55
+ let metric_ton = Weight :: from_metric_tons (1.0 );
56
+ let united_states_tons = metric_ton . as_short_tons ();
57
+ let united_states_pounds = metric_ton . as_pounds ();
58
+ println! (" One metric ton is {} U.S. tons - that's {} pounds!" , united_states_tons , united_states_pounds );
59
+
60
+ // Volumes!
61
+ let gallon = Volume :: from_gallons (1.0 );
62
+ let pint = Volume :: from_pints (1.0 );
63
+ let beers = gallon / pint ;
64
+ println! (" A gallon of beer will pour {:.1} pints!" , beers );
65
+
66
+ // Pressures!
67
+ let atmosphere = Pressure :: from_atmospheres (1.0 );
68
+ println! (" Earth's atmosphere is usually {} psi" , atmosphere . as_psi ());
69
+ }
63
70
```
64
71
65
72
--------------------------------------
0 commit comments