Skip to main content

ruvix_types/
object.rs

1//! Kernel object type enumeration.
2//!
3//! Every kernel object has a type that determines what operations are valid
4//! and what capabilities are required to access it.
5
6/// The type of a kernel object.
7///
8/// RuVix has a fixed set of kernel object types. All other abstractions
9/// (file systems, networking, device drivers, vector indexes, graph engines,
10/// AI inference) are RVF components running in user space.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
12#[repr(u8)]
13pub enum ObjectType {
14    /// A task (unit of concurrent execution with capability set).
15    Task = 0,
16
17    /// A memory region with access policy (immutable, append-only, slab).
18    Region = 1,
19
20    /// A typed ring buffer for inter-task communication.
21    Queue = 2,
22
23    /// A deadline-driven scheduling primitive.
24    Timer = 3,
25
26    /// A kernel-resident vector store with HNSW indexing.
27    VectorStore = 4,
28
29    /// A kernel-resident graph store with mincut partitioning.
30    GraphStore = 5,
31
32    /// A mounted RVF package in the component namespace.
33    RvfMount = 6,
34
35    /// A capability table entry.
36    Capability = 7,
37
38    /// The kernel witness log (append-only attestation log).
39    WitnessLog = 8,
40
41    /// A sensor subscription for RuView perception events.
42    Subscription = 9,
43}
44
45impl ObjectType {
46    /// Returns a human-readable name for the object type.
47    #[inline]
48    #[must_use]
49    pub const fn as_str(&self) -> &'static str {
50        match self {
51            Self::Task => "Task",
52            Self::Region => "Region",
53            Self::Queue => "Queue",
54            Self::Timer => "Timer",
55            Self::VectorStore => "VectorStore",
56            Self::GraphStore => "GraphStore",
57            Self::RvfMount => "RvfMount",
58            Self::Capability => "Capability",
59            Self::WitnessLog => "WitnessLog",
60            Self::Subscription => "Subscription",
61        }
62    }
63
64    /// Converts from a raw u8 value.
65    #[inline]
66    #[must_use]
67    pub const fn from_u8(value: u8) -> Option<Self> {
68        match value {
69            0 => Some(Self::Task),
70            1 => Some(Self::Region),
71            2 => Some(Self::Queue),
72            3 => Some(Self::Timer),
73            4 => Some(Self::VectorStore),
74            5 => Some(Self::GraphStore),
75            6 => Some(Self::RvfMount),
76            7 => Some(Self::Capability),
77            8 => Some(Self::WitnessLog),
78            9 => Some(Self::Subscription),
79            _ => None,
80        }
81    }
82}
83
84#[cfg(test)]
85mod tests {
86    use super::*;
87
88    #[test]
89    fn test_object_type_roundtrip() {
90        for i in 0..=9 {
91            let ot = ObjectType::from_u8(i).unwrap();
92            assert_eq!(ot as u8, i);
93        }
94    }
95
96    #[test]
97    fn test_object_type_invalid() {
98        assert!(ObjectType::from_u8(10).is_none());
99        assert!(ObjectType::from_u8(255).is_none());
100    }
101}