verit-core 0.1.0

Internal: portable core engine for Exavian Veritate. Not a public API — depend on `verit`.
Documentation
//! Dynamic values for the write path. The prototype has no codegen; you build
//! a `Value` tree against a runtime [`crate::Schema`] and encode it. A struct
//! value lists (field id, value) pairs — omitted fields are absent (their
//! presence bit stays 0 and readers see `None`).

#[derive(Clone, Debug, PartialEq)]
pub enum Value {
    Bool(bool),
    U8(u8),
    U16(u16),
    U32(u32),
    U64(u64),
    I8(i8),
    I16(i16),
    I32(i32),
    I64(i64),
    F32(f32),
    F64(f64),
    Str(String),
    Bytes(Vec<u8>),
    /// Raw enum value; enums are open, so this need not name a known variant.
    Enum(u32),
    List(Vec<Value>),
    /// (field id, value) pairs. Order does not matter; duplicate ids are an
    /// encode-time error.
    Struct(Vec<(u16, Value)>),
    /// (key, value) entries. Order does not matter — the encoder sorts entries
    /// by key into canonical order; duplicate keys are an encode-time error.
    Map(Vec<(Value, Value)>),
    /// A `union` value: the variant tag (index into the schema's variant list)
    /// and that variant's value.
    Union(u32, Box<Value>),
}

impl Value {
    pub fn str(s: &str) -> Value {
        Value::Str(s.to_string())
    }

    pub fn kind(&self) -> &'static str {
        match self {
            Value::Bool(_) => "bool",
            Value::U8(_) => "u8",
            Value::U16(_) => "u16",
            Value::U32(_) => "u32",
            Value::U64(_) => "u64",
            Value::I8(_) => "i8",
            Value::I16(_) => "i16",
            Value::I32(_) => "i32",
            Value::I64(_) => "i64",
            Value::F32(_) => "f32",
            Value::F64(_) => "f64",
            Value::Str(_) => "string",
            Value::Bytes(_) => "bytes",
            Value::Enum(_) => "enum",
            Value::List(_) => "list",
            Value::Struct(_) => "struct",
            Value::Map(_) => "map",
            Value::Union(..) => "union",
        }
    }
}