File: unit.rs

package info (click to toggle)
rust-uom 0.37.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,368 kB
  • sloc: makefile: 2
file content (34 lines) | stat: -rw-r--r-- 806 bytes parent folder | download | duplicates (2)
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
//! Example showing how to use the `unit!` macro to add new units to existing quantities.
//!
//! [Pull requests](https://github.com/iliekturtles/uom/pulls) for new units are always greatly
//! appreciated.

#[macro_use]
extern crate uom;

use uom::fmt::DisplayStyle::*;
use uom::si::f32::*;
use uom::si::length::meter;

unit! {
    system: uom::si;
    quantity: uom::si::length;

    @smoot: 1.702; "smoot", "smoot", "smoots";
}

fn main() {
    let l1 = Length::new::<meter>(15.0);
    let l2 = Length::new::<smoot>(1.0);

    println!(
        "{} = {}",
        l1.into_format_args(meter, Abbreviation),
        l1.into_format_args(smoot, Abbreviation)
    );
    println!(
        "{} = {}",
        l2.into_format_args(smoot, Abbreviation),
        l2.into_format_args(meter, Abbreviation)
    );
}