unit_system

Crates.iounit_system
lib.rsunit_system
version0.1.0
sourcesrc
created_at2022-01-28 09:53:03.377824
updated_at2022-01-28 09:53:03.377824
descriptionAutomatically derived typed unit systems.
homepage
repositoryhttps://github.com/carrascomj/unit_system
max_upload_size
id523010
size7,611
Jorge Carrasco (carrascomj)

documentation

README

Crates.io Documentation CI

unit_system

Automatically derived typed Unit system with conversions.

Example

use unit_system::prelude::*;

#[derive(Unit)]
pub struct Meter(pub f32);
#[derive(Unit)]
pub struct Inch(pub f64);

// we can convert between any `Unit`s whose bases define BaseIntoBase
impl BaseIntoBase<Inch> for Meter {
  fn convert_base(self) -> Inch {
     Inch(self.0 as f64 * 40.)
  }
}

// CMeter, DMeter, HMeter, NMeter... have been automatically built
let centimeters: CMeter = CMeter(3.);
// the same for inches (non-SI units would require manual impls of Unit)
let kilo_inches: KInch = centimeters.convert_outer();

// KInch{ 0.012. }
println!("{:?}", kilo_inches);
assert!(f64::abs(kilo_inches.0 - 0.0012) < 1e-7);

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

README.md is automatically generated on CI using cargo-readme. Please, modify README.tpl or lib.rs instead (check the github worflow for more details).

Commit count: 8

cargo fmt