Closed MarkSwanson closed 2 years ago
You can get the underlying value by accessing the value_unsafe
field, and enforce it's an energy with a type bound as so:
fn print_joule<T: Display>(energy: Joule<T>) {
println!("{} J", energy.value_unsafe)
}
Alternatively, you could divide by 1 Joule:
let x = Joule::new(10.0);
println!("{} J", x / Joule::new(1.0));
Got it. I like the second one as if I see anything other than Joules I know I've messed up my units. Thanks!
I have a function like: fn() -> Joules. However, when I print the Joules value I get something like: 5 m^2kgs^-2 Is there an easy way to print '5 Joules' instead?
If not, what do you think a good solution to this would be? (I'm not seeing an easy way to get access to the units to compare the set of units against 'Joule' etc.) I'd be happy to take a crack at it. Thanks!