-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial changes to create a unit!
macro.
#209
Conversation
//! Example showing how to use the `unit!` macro to add new units to existing quantities. | ||
|
||
#[macro_use] | ||
extern crate uom; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe using the macro directly like
use uom::unit;
now that we are using edition 2018?
/// executed. `@...` match arms are considered private. | ||
/// | ||
/// * `$unit`: Unit name (e.g. `meter`, `foot`). | ||
/// * `$conversion`: Conversion (coefficient and constant factor) from the unit to the base unit of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wording of "constant factor" did puzzle me a bit during the first reading as "factor" suggests a product where a sum is computed. AFAIU, this is something like an offset or an intercept?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most units just use a coefficient. The constant factor is for thermodynamic temperature. Thoughts on better wording?
uom/src/si/thermodynamic_temperature.rs
Lines 90 to 93 in 1a3386a
@degree_celsius: 1.0_E0, 273.15_E0; "°C", "degree Celsius", "degrees Celsius"; | |
@degree_fahrenheit: 5.0_E0 / 9.0_E0, 459.67_E0; "°F", "degree Fahrenheit", | |
"degrees Fahrenheit"; | |
@degree_rankine: 5.0_E0 / 9.0_E0; "°R", "degree Rankine", "degrees Rankine"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest something along the lines of offset or intercept.
e68090c
to
2f756d2
Compare
Latest changes now ready for review. I ended up stopping short of making the quantity! macro be able to be executed outside of direct submodules of the location where the system! macro was executed. Executing quantity! in an external crate runs into issues with attempting to implement external traits for external types and needing access to private items. |
2f756d2
to
d9e781c
Compare
Note to self: Update the documentation to state that PRs for any new units are desired. |
d9e781c
to
351bfaa
Compare
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.
351bfaa
to
7c3d036
Compare
Additional changes still pending to allow the
quantity!
macro to alsobe called outside the mod where the
system!
macro was called.