uom icon indicating copy to clipboard operation
uom copied to clipboard

Example on embedding into a struct?

Open ChristopherRabotin opened this issue 4 years ago • 3 comments

Hi there,

I'm considering using uom for hifitime and nyx, but I would like to be able to specify that a given structure stores the data in a given time.

For example, in hifitime, I have an Epoch simply defined as pub struct Epoch(f64);. I'm trying to store a second (e.g. pub struct Epoch(si::time::second);). However, the documentation and the examples don't seem to help me much as to how I should define this structure.

How would I go about implementing that?

Thanks

ChristopherRabotin avatar Apr 21 '20 07:04 ChristopherRabotin

uom works in quantities (time, length, ...) rather than units (second, meter, ...) so you don't put a second member in your struct, but a Time member. Quantities store their value using the base unit, which in this case is second, so you can just include a Time member.

If you happened to want storage to use a different base unit you can define new type aliases with the ISQ! macro as shown in https://github.com/iliekturtles/uom/blob/master/examples/base.rs.

Long term I'm looking to change the decision of always working with quantities. See #107 for the details and some of the work that I've done.

iliekturtles avatar Apr 22 '20 14:04 iliekturtles

It's not really clear from the documentation the type of, for example, Length::new::<meter>(15.0); or Time::new::<second>(10.0), an example with explicit types would make this clearer

AidanConnelly avatar Feb 21 '21 22:02 AidanConnelly

Thanks for the suggestion. I agree it can get confusing.

For reference types like Length or Time are just aliases to Quantity with that quantity's dimension filled into Quantity's D generic parameter.

iliekturtles avatar Feb 22 '21 13:02 iliekturtles