-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow new units to be defined using
unit!
outside of quantity!
.
The new `unit!` macro allows for new units to be defined outside of the `quantity!` macro. Units defined using this macro will not be included in the quantity unit enum or associated functions, or in the `FromStr` implementation. Using this macro will create submodules for the underlying storage types that are enabled (e.g. `mod f32`). Resolves #173.
- Loading branch information
1 parent
5f31ced
commit 0e597dd
Showing
7 changed files
with
350 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.