Skip to content

Add set function #513

@G0rocks

Description

@G0rocks

Hello

I'm new to this crate and just used the get function to get the value of a variable in the specified unit I wanted (great) but now I want to set a variable to a specific value in a unit.

Now when I search the docs for "get" there are a lot of results but when I search for "set" the results are actually the same as when you type "get".

I originally tried doing:

dist.set::<uom::si::length::meter>(0.0);

Which I feel like is an okay intuitive way to do it but got the error message

no method named `set` found for struct `Quantity` in the current scope

So I tried the next intuitive way which is

dist = uom::si::f64::Length::meter(0.0);

which yielded

error[E0599]: no function or associated item named `meter` found for struct `Quantity` in the current scope

So finally I did

dist = uom::si::f64::Length::new::<uom::si::length::meter>(0.0);

Which isn't the simplest or easiest way of using a variable that's already been declared, here's how I define the variable:

let mut dist: uom::si::f64::Length = uom::si::f64::Length::new::<uom::si::length::meter>(0.0);

So I suggest implementing a set function so that you can write

dist.set(uom::si::length::meter,0.0);

Or similar.

Also since my tone isn't heard very well across this text, I'm very pleased that this crate exists, it's very helpful for keeping my units in check!
I'm just a reformist so often when I see an opportunity for improvement I like to suggest it ^_^

Thank you :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions