-
Notifications
You must be signed in to change notification settings - Fork 127
Description
I often have to construct quantities outright for simulation and I think its more verbose than it should be, especially for very common units. I have implemented a trait in my own repos that can convert the standard numerical types into lengths like this
assert_eq!(
5.cm(),
Length::new::<centimeter>(5.)
);
assert_eq!(
16.4.ft(),
Length::new::<foot>(16.4)
);(have a look at this for how it is implemented)
I have asked @iliekturtles if this would be something that could be implemented into uom directly and this was his response:
I think a trait like this, possibly implemented behind a feature gate, would be useful. Please go ahead and open an issue. A PR to implement is also very welcome.
At a high level I'm thinking a To$Quantity trait could be implemented in https://github.com/iliekturtles/uom/blob/master/src/quantity.rs with a method for each unit. I've skipped over the complications of the U and V generic parameters, but believe we should be able to work through these.
fn $unit(self) -> $quantity<...> {
$quantity::new<$unit>(self)
}
So that is why I am opening this issue. I will try to implement it myself this or next week and open a PR if I manage.