Skip to content
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

Merged
merged 1 commit into from
Dec 28, 2020
Merged

Conversation

iliekturtles
Copy link
Owner

Additional changes still pending to allow the quantity! macro to also
be called outside the mod where the system! macro was called.

//! Example showing how to use the `unit!` macro to add new units to existing quantities.

#[macro_use]
extern crate uom;
Copy link
Contributor

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
Copy link
Contributor

@adamreichold adamreichold Oct 6, 2020

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?

Copy link
Owner Author

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?

@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";

Copy link
Contributor

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.

@iliekturtles iliekturtles force-pushed the 173-new-units branch 2 times, most recently from e68090c to 2f756d2 Compare November 28, 2020 00:21
@iliekturtles
Copy link
Owner Author

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.

@iliekturtles
Copy link
Owner Author

Note to self: Update the documentation to state that PRs for any new units are desired.

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.
@iliekturtles iliekturtles merged commit 0e597dd into master Dec 28, 2020
@iliekturtles iliekturtles deleted the 173-new-units branch December 28, 2020 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants