-
use uom::si::f32::Length;
use uom::si::length::millimeter;
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug)]
struct Unit {
// length is in millimeter but the base unit of Length is meter
length: Length,
}
fn main() {
let data = r#"
{
"length": 0.4
}"#;
let v: Unit = serde_json::from_str(data).unwrap();
dbg!(v);
}
// Output
[src/main.rs:26] v = Unit {
length: 0.4 m^1,
} Upon deserialization, how do I specify |
Beta Was this translation helpful? Give feedback.
Answered by
Laifsyn
Aug 18, 2024
Replies: 1 comment
-
Maybe you're looking for this // 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);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
chungwong
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.