frdt 0.2.4

Edit and inspect Resonite FrDT (.brson) documents without expanding them to JSON
Documentation
/// Three IEEE-754 doubles, stored as a BSON document `{x, y, z}`.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Float3 {
    pub x: f64,
    pub y: f64,
    pub z: f64,
}

/// Four IEEE-754 doubles, stored as a BSON document `{x, y, z, w}`.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct FloatQ {
    pub x: f64,
    pub y: f64,
    pub z: f64,
    pub w: f64,
}

/// A slot field value that can be written without going through JSON.
#[derive(Debug, Clone, PartialEq)]
pub enum Value {
    F64(f64),
    Float3(Float3),
    FloatQ(FloatQ),
    String(String),
    I64(i64),
    Bool(bool),
}

/// Build a `float3` slot value such as `Scale`.
pub fn float3(x: f64, y: f64, z: f64) -> Value {
    Value::Float3(Float3 { x, y, z })
}

/// Build a quaternion slot value such as `Rotation`.
pub fn floatq(x: f64, y: f64, z: f64, w: f64) -> Value {
    Value::FloatQ(FloatQ { x, y, z, w })
}

/// A scalar or small aggregate read from a Dynamic Variable field.
///
/// Non-finite doubles stay IEEE values. They are never turned into strings.
#[derive(Debug, Clone, PartialEq)]
pub enum DynValue {
    F64(f64),
    I64(i64),
    Bool(bool),
    String(String),
    Float3(Float3),
    FloatQ(FloatQ),
    Null,
}

impl DynValue {
    pub fn as_f64(&self) -> Option<f64> {
        match self {
            DynValue::F64(v) => Some(*v),
            DynValue::I64(v) => Some(*v as f64),
            _ => None,
        }
    }

    pub fn as_str(&self) -> Option<&str> {
        match self {
            DynValue::String(s) => Some(s),
            _ => None,
        }
    }
}