File: mks.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 (88 lines) | stat: -rw-r--r-- 1,738 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! Example showing how to create a custom system of quantities.

#[macro_use]
extern crate uom;

use crate::length::{foot, meter};
use uom::fmt::DisplayStyle::Abbreviation;

fn main() {
    let l1 = f32::Length::new::<meter>(100.0);

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

#[macro_use]
mod length {
    quantity! {
        /// Length (base unit meter, m).
        quantity: Length; "length";
        /// Length dimension, m.
        dimension: Q<
            P1,  // length
            Z0,  // mass
            Z0>; // time
        units {
            @meter: 1.0E0; "m", "meter", "meters";
            @foot: 3.048E-1; "ft", "foot", "feet";
        }
    }
}

#[macro_use]
mod mass {
    quantity! {
        /// Mass (base unit kilogram, kg).
        quantity: Mass; "mass";
        /// Mass dimension, kg.
        dimension: Q<
            Z0,  // length
            P1,  // mass
            Z0>; // time
        units {
            @kilogram: 1.0; "kg", "kilogram", "kilograms";
        }
    }
}

#[macro_use]
mod time {
    quantity! {
        /// Time (base unit second, s).
        quantity: Time; "time";
        /// Time dimension, s.
        dimension: Q<
            Z0,  // length
            Z0,  // mass
            P1>; // time
        units {
            @second: 1.0; "s", "second", "seconds";
        }
    }
}

system! {
    quantities: Q {
        length: meter, L;
        mass: kilogram, M;
        time: second, T;
    }

    units: U {
        mod length::Length,
        mod mass::Mass,
        mod time::Time,
    }
}

mod f32 {
    mod mks {
        pub use super::super::*;
    }

    Q!(self::mks, f32);
}