Skip to content

Changing base unit in Length #470

Answered by Laifsyn
chungwong asked this question in Q&A
Discussion options

You must be logged in to vote

Maybe you're looking for this
As answered by the maintainer: #390 (comment), you can go to examples/base.rs to see a minimal example.

// Add missing imports.
mod custom_milli {
    ISQ!(
        uom::si,
        f32,
        (millimeter /* Now its base number is millimeter */, gram, second, ampere, kelvin, mole, candela)
    );
}

#[derive(Serialize, Deserialize, Debug)]
struct Unit {
    // Update to use a Length based on milimeter
    length: custom_milli::Length,
}

// All copied pasted from your's comment here below

fn main() {
    let data = r#"
    {
        "length": 0.4
    }"#;

    let v: Unit = serde_json::from_str(data).unwrap();

    dbg!(v);
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by chungwong
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants