Skip to main content

sim_lib_view_device/
ladder.rs

1//! Ordered device tiers derived from open surface metadata.
2
3use sim_kernel::Symbol;
4
5/// The capability ladder for small and wearable surfaces.
6///
7/// The order is meaningful: a higher tier can satisfy requirements for any
8/// lower tier. The variants are not concrete device kinds.
9#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
10pub enum DeviceTier {
11    /// A display-only surface can show a reduced glance or pane.
12    Display,
13    /// A sensor surface contributes live stream fields but does not act back.
14    Sensor,
15    /// An actuator surface can emit haptics, HUD output, face output, or sound.
16    Actuator,
17    /// A rich surface combines high-rate display with pose or equivalent stream
18    /// data.
19    Rich,
20}
21
22impl DeviceTier {
23    /// Every tier in ascending capability order.
24    pub const ALL: [DeviceTier; 4] = [
25        DeviceTier::Display,
26        DeviceTier::Sensor,
27        DeviceTier::Actuator,
28        DeviceTier::Rich,
29    ];
30
31    /// The stable token used in profile expressions.
32    pub fn token(self) -> &'static str {
33        match self {
34            DeviceTier::Display => "display",
35            DeviceTier::Sensor => "sensor",
36            DeviceTier::Actuator => "actuator",
37            DeviceTier::Rich => "rich",
38        }
39    }
40
41    /// Encodes the tier as an unqualified symbol.
42    pub fn to_symbol(self) -> Symbol {
43        Symbol::new(self.token())
44    }
45
46    /// Parses an unqualified tier symbol.
47    pub fn from_symbol(symbol: &Symbol) -> Option<Self> {
48        match symbol.name.as_ref() {
49            "display" if symbol.namespace.is_none() => Some(DeviceTier::Display),
50            "sensor" if symbol.namespace.is_none() => Some(DeviceTier::Sensor),
51            "actuator" if symbol.namespace.is_none() => Some(DeviceTier::Actuator),
52            "rich" if symbol.namespace.is_none() => Some(DeviceTier::Rich),
53            _ => None,
54        }
55    }
56
57    /// Returns true when this tier can satisfy a requirement for `required`.
58    pub fn supports(self, required: DeviceTier) -> bool {
59        self >= required
60    }
61}