vexil-codegen-rust 0.4.3

Rust code generation backend for the Vexil schema compiler
Documentation
// Code generated by vexilc. DO NOT EDIT.
// Source: test.enums

use vexil_runtime::*;

pub const SCHEMA_HASH: [u8; 32] = [0x8a, 0xc5, 0x25, 0xce, 0x0a, 0xec, 0xba, 0x7a, 0xf1, 0x28, 0xaf, 0x30, 0xbc, 0x21, 0x43, 0xe0, 0xfa, 0x59, 0x1b, 0x4a, 0x62, 0xf6, 0xd7, 0x19, 0x90, 0x74, 0xe9, 0xca, 0x84, 0x9e, 0x34, 0x68];

// ── Direction ──
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u64)]
pub enum Direction {
    North = 0_u64,
    South = 1_u64,
    East = 2_u64,
    West = 3_u64,
}

impl vexil_runtime::Pack for Direction {
    fn pack(&self, w: &mut vexil_runtime::BitWriter) -> Result<(), vexil_runtime::EncodeError> {
        let disc: u64 = match self {
            Self::North => 0_u64,
            Self::South => 1_u64,
            Self::East => 2_u64,
            Self::West => 3_u64,
        };
        w.write_bits(disc, 2_u8);
        Ok(())
    }
}

impl vexil_runtime::Unpack for Direction {
    fn unpack(r: &mut vexil_runtime::BitReader<'_>) -> Result<Self, vexil_runtime::DecodeError> {
        let disc = r.read_bits(2_u8)?;
        match disc {
            0_u64 => Ok(Self::North),
            1_u64 => Ok(Self::South),
            2_u64 => Ok(Self::East),
            3_u64 => Ok(Self::West),
            _ => Err(vexil_runtime::DecodeError::UnknownEnumVariant { type_name: "Direction", value: disc }),
        }
    }
}


// ── ClientKind ──
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ClientKind {
    Renderer,
    Agent,
    Plugin,
    Shell,
    Unknown(u64),
}

impl vexil_runtime::Pack for ClientKind {
    fn pack(&self, w: &mut vexil_runtime::BitWriter) -> Result<(), vexil_runtime::EncodeError> {
        let disc: u64 = match self {
            Self::Renderer => 0_u64,
            Self::Agent => 1_u64,
            Self::Plugin => 2_u64,
            Self::Shell => 3_u64,
            Self::Unknown(v) => *v,
        };
        w.write_bits(disc, 8_u8);
        Ok(())
    }
}

impl vexil_runtime::Unpack for ClientKind {
    fn unpack(r: &mut vexil_runtime::BitReader<'_>) -> Result<Self, vexil_runtime::DecodeError> {
        let disc = r.read_bits(8_u8)?;
        match disc {
            0_u64 => Ok(Self::Renderer),
            1_u64 => Ok(Self::Agent),
            2_u64 => Ok(Self::Plugin),
            3_u64 => Ok(Self::Shell),
            other => Ok(Self::Unknown(other)),
        }
    }
}


// ── HardwareStatus ──
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u64)]
pub enum HardwareStatus {
    Ok = 0_u64,
    Warn = 1_u64,
    Fault = 2_u64,
}

impl vexil_runtime::Pack for HardwareStatus {
    fn pack(&self, w: &mut vexil_runtime::BitWriter) -> Result<(), vexil_runtime::EncodeError> {
        let disc: u64 = match self {
            Self::Ok => 0_u64,
            Self::Warn => 1_u64,
            Self::Fault => 2_u64,
        };
        w.write_bits(disc, 16_u8);
        Ok(())
    }
}

impl vexil_runtime::Unpack for HardwareStatus {
    fn unpack(r: &mut vexil_runtime::BitReader<'_>) -> Result<Self, vexil_runtime::DecodeError> {
        let disc = r.read_bits(16_u8)?;
        match disc {
            0_u64 => Ok(Self::Ok),
            1_u64 => Ok(Self::Warn),
            2_u64 => Ok(Self::Fault),
            _ => Err(vexil_runtime::DecodeError::UnknownEnumVariant { type_name: "HardwareStatus", value: disc }),
        }
    }
}


// ── Sparse ──
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u64)]
pub enum Sparse {
    Low = 0_u64,
    High = 1000_u64,
}

impl vexil_runtime::Pack for Sparse {
    fn pack(&self, w: &mut vexil_runtime::BitWriter) -> Result<(), vexil_runtime::EncodeError> {
        let disc: u64 = match self {
            Self::Low => 0_u64,
            Self::High => 1000_u64,
        };
        w.write_bits(disc, 32_u8);
        Ok(())
    }
}

impl vexil_runtime::Unpack for Sparse {
    fn unpack(r: &mut vexil_runtime::BitReader<'_>) -> Result<Self, vexil_runtime::DecodeError> {
        let disc = r.read_bits(32_u8)?;
        match disc {
            0_u64 => Ok(Self::Low),
            1000_u64 => Ok(Self::High),
            _ => Err(vexil_runtime::DecodeError::UnknownEnumVariant { type_name: "Sparse", value: disc }),
        }
    }
}


// ── Lifecycle ──
// REMOVED @1 (since unknown): Replaced by Suspended
pub const LIFECYCLE_REMOVED_ORDINALS: &[(u16, &str, &str)] = &[
    (1, "unknown", "Replaced by Suspended"),
];
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u64)]
pub enum Lifecycle {
    Active = 0_u64,
    Pending = 2_u64,
}

impl vexil_runtime::Pack for Lifecycle {
    fn pack(&self, w: &mut vexil_runtime::BitWriter) -> Result<(), vexil_runtime::EncodeError> {
        let disc: u64 = match self {
            Self::Active => 0_u64,
            Self::Pending => 2_u64,
        };
        w.write_bits(disc, 2_u8);
        Ok(())
    }
}

impl vexil_runtime::Unpack for Lifecycle {
    fn unpack(r: &mut vexil_runtime::BitReader<'_>) -> Result<Self, vexil_runtime::DecodeError> {
        let disc = r.read_bits(2_u8)?;
        match disc {
            0_u64 => Ok(Self::Active),
            2_u64 => Ok(Self::Pending),
            _ => Err(vexil_runtime::DecodeError::UnknownEnumVariant { type_name: "Lifecycle", value: disc }),
        }
    }
}