Open joe-saronic opened 4 months ago
I didn't have a chance to fully go through your code and try to compile locally to resolve the errors. My guess right now is that type constraints are missing and compiler isn't explicitly calling them out.
Is there any reason you want to store the data as buf: [f64; 2],
and not buf: [Quantity<D, SI<f64>, f64>; 2],
? Doing this would skip the need to construct and deconstruct the types and reduce the need for constraints.
@iliekturtles Thanks for looking into this. The arrays in this code are a standin for nalgebra::Vector2
, which is what I'm really using. I didn't think the particular type was related to the issue, but I'll definitely try to make a vector of quantities.
@iliekturtles That being said, is there a way to convert an f64
and a Units
to a quantity of the appropriate dimension somehow? It seems like this should be possible, but I haven't had any luck figuring it out.
I have had a hard time understanding how to get Dimension
from a Units
, and how the Conversion
trait really works for arbitrary cases. I suspect that it's tied to the answer somehow.
If you know the quantity (Length
in the example below), you can explicitly provide the dimension, underlying storage type, and unit to create a quantity. There isn't a way to get the dimension when you just have a unit.
use uom::si::length as l;
use uom::si::*;
fn main() {
let x = Quantity::<l::Dimension, SI<f32>, f32>::new::<l::meter>(5.0);
println!("{:?}", x); // 5.0 m^1
}
The issue is that I don't have the quantity available initially. Is there a way to get the mapping between meter
and length::Dimension
somehow?
I'm new to rust and very new to UOM, so admittedly, this is likely user error caused by a lack of understanding. This is a followup from my StackOverflow post, which got no traction unfortunately.
I am trying to make a simple type that will be backed by an array in the default units of a given dimension. The idea is pretty simple: I provide a constructor that converts quantities to base units and getters that convert them back to desired units for some given dimension:
I end up with a couple of different errors that I can't quite make sense of:
I am having trouble understanding what is going on here because I was under the impression that there is a blanket implementation of
new
forQuantity
, but apparently that's not the case.If I comment out the lines with
Quantity::<D, SI<f64>, f64>::new::<U>(...).value,
, e.g. like0.0, //Quantity::<D, SI<f64>, f64>::new::<U>(x).value,
, the debug error still persists:I have had a hard time finding a good tutorial for UOM. My issue is that while the crate is well documented and thorough, it appears to assume a certain level of prior knowledge that I simply don't have.