diff --git a/README.md b/README.md index 47e65aa2..0b53b7ce 100644 --- a/README.md +++ b/README.md @@ -43,15 +43,33 @@ operations: extern crate uom; use uom::si::f32::*; -use uom::si::length::kilometer; -use uom::si::time::second; +use uom::si::length::{kilometer, meter}; +use uom::si::time::{minute, second}; +use uom::si::velocity::meter_per_second; fn main() { + // Create quantities let length = Length::new::(5.0); let time = Time::new::(15.0); let velocity/*: Velocity*/ = length / time; let _acceleration = calc_acceleration(velocity, time); //let error = length + time; // error[E0308]: mismatched types + + // Perfrom unit conversions + assert_eq!(length.get::(), 5_000.0); + assert_eq!(time.get::(), 0.25); + + // Setup re-usable format arguments for quantities + let m = Length::format_args(meter, Abbreviation); + let s = Time::format_args(second, Abbreviation); + + // Print results of simple formulas using different output units. + println!( + "{} / {} = {}", + m.with(length), + s.with(time), + velocity.into_format_args(meter_per_second, Abbreviation) // One-off quantity formatting. + ); } fn calc_acceleration(velocity: Velocity, time: Time) -> Acceleration { diff --git a/examples/si.rs b/examples/si.rs index 7a5bd0fd..7b703951 100644 --- a/examples/si.rs +++ b/examples/si.rs @@ -2,18 +2,23 @@ use uom::fmt::DisplayStyle::Abbreviation; use uom::si::f32::*; -use uom::si::length::{centimeter, kilometer, meter}; -use uom::si::time::second; +use uom::si::length::{centimeter, kilometer, meter, millimeter}; +use uom::si::time::{minute, second}; use uom::si::velocity::{kilometer_per_second, meter_per_second}; fn main() { // Setup length and time quantities using different units. let l1 = Length::new::(15.0); let l2 = Length::new::(10.0); - let t1 = Time::new::(50.0); + let t1 = Time::new::(60.0); let v1 = l1 / t1; //let error = l1 + t1; // error[E0308]: mismatched types + // Perfrom unit conversions + assert_eq!(l1.get::().round(), 1_500.0); + assert_eq!(l2.get::().round(), 100.0); + assert_eq!(t1.get::().round(), 1.0); + // Setup re-usable format arguments. let m = Length::format_args(meter, Abbreviation); let cm = Length::format_args(centimeter, Abbreviation);