-
Notifications
You must be signed in to change notification settings - Fork 97
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
Conversion between Equivalent quantities with different underlying types #293
Comments
Of course, it is possible to do something like use uom::si::length::meter as arbitrary_conversion_unit;
Ulength::new::<arbitrary_conversion_unit>(b.get::<arbitrary_conversion_unit>() as usize); but I'm hoping that there's a less ad-hoc, higher-level approach available. |
Note that the fields of pub fn as_discrete_length(value: FLength) -> ULength {
Quantity {
dimension: PhantomData,
units: PhantomData,
value: value.value as usize,
}
} and possibly a generic extension by using some trait like |
Posting questions as issue is the best way right now. It gives us a public record for anyone who may have a similar question in the future, allows others like to respond (@adamreichold has been right on this), and is, in some ways, an indication that documentation could be improved. I also haven't taken the time to see about enabling GitHub discussions (feedback on this last part welcome). Both of the solutions mentioned so far work short-term, but I think long term the right solution is a conversion trait that takes advantage of pub trait QuantityCast: ... {
fn from<...>(q: ...) -> Option<Self>;
} use uom::si::f32::Length as Flength;
use uom::si::usize::Length as Ulength;
let a: Flength = todo!();
let b = a.floor();
let c: Ulength = Ulength::from(b); |
Realized I never responded to this. Unfortunately I don't have much wisdom to impart. My strategy is to try ignoring everything between the |
One one occasion, IIRC, the only relevant information anywhere in the error message was the presence/absence of a single On another, the information was the difference between Perhaps more obviously, when the error concerns a mismatch between quantities, if you understand how I wonder whether it would be feasible to implement a parser and translator---in the spirit of
and turn it into something like this:
maybe with an option for including the base units. |
Does |
into this
(alignment mine) which is almost nothing on the scale of the total amount of noise. All it does is things like
If all that noise can be reduced to something like this |
Thanks for the initial analysis. I split the request into a separate issue in case anyone gets the time and desire to implement. |
(Is opening issues here, appropriate for asking questions about usage of
uom
? Is there some better place for discussions or asking for help?)In my
uom
-less code, I have something that amounts to:Let's say that
a
,b
andc
are allLength
s. How should this code be made unit-aware? I start off with something like this:as
cannot work for non-primitives, and my attempts to use any of theFrom
machinery result in very noisy compiler error messages which amount toGoing off on a tangent, do you have any words of wisdom regarding extracting the signal from the almost pure noise in such error messages?
The text was updated successfully, but these errors were encountered: