| Crates.io | xrunits |
| lib.rs | xrunits |
| version | 0.1.2 |
| created_at | 2021-08-21 22:34:27.521569+00 |
| updated_at | 2021-08-21 23:06:09.525192+00 |
| description | A strong type unit library |
| homepage | |
| repository | https://github.com/xstater/xrunits |
| max_upload_size | |
| id | 440476 |
| size | 19,178 |
XRUnits is a unit library
We usually use some real-world unit. If we need to develop a program to deal with these units, like creating a downloader which need to calculate the data transfer speed or set the frequency of MCU,we need do lots of duplicate works to convert these unit, so I want to develop a unit library with STRONG TYPE and Easily using to deal with these situations.
To avoid duplicate code,I use lots of macro to automatically generate code.
To create 2Kg
# use xrunits::mass::BuildKilogram;
let mass = 2.kg();
Convert it to ton and gram
# use xrunits::mass::{Ton, BuildKilogram, Gram};
# use xrunits::CastTo;
let mass : Ton = 2.kg().cast_to();
let mass : Gram = mass.cast_to();
Print to screen
# use xrunits::time::BuildSecond;
println!("time:{}",3.sec()); //time:3s
Calculate the Frequency from Period
# use xrunits::time::{BuildMicrosecond, IntoFrequency};
# use xrunits::frequency::Megahertz;
let us = 1.us();
let mhz : Megahertz = us.into_frequency();