use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(u8)]
pub enum YLayer {
Prose = 0,
Semantic = 1,
Reasoning = 2,
Experience = 3,
Journal = 4,
Procedural = 5,
Metacognitive = 6,
}
impl YLayer {
pub const ALL: [YLayer; 7] = [
YLayer::Prose,
YLayer::Semantic,
YLayer::Reasoning,
YLayer::Experience,
YLayer::Journal,
YLayer::Procedural,
YLayer::Metacognitive,
];
pub const DEFINITIONAL: [YLayer; 3] = [YLayer::Prose, YLayer::Semantic, YLayer::Reasoning];
pub const EXPERIENTIAL: [YLayer; 4] = [
YLayer::Experience,
YLayer::Journal,
YLayer::Procedural,
YLayer::Metacognitive,
];
pub fn as_u8(self) -> u8 {
self as u8
}
pub fn from_u8(v: u8) -> Option<YLayer> {
match v {
0 => Some(YLayer::Prose),
1 => Some(YLayer::Semantic),
2 => Some(YLayer::Reasoning),
3 => Some(YLayer::Experience),
4 => Some(YLayer::Journal),
5 => Some(YLayer::Procedural),
6 => Some(YLayer::Metacognitive),
_ => None,
}
}
pub fn is_definitional(self) -> bool {
(self as u8) <= 2
}
pub fn is_experiential(self) -> bool {
(self as u8) >= 3
}
pub fn name(self) -> &'static str {
match self {
YLayer::Prose => "Prose",
YLayer::Semantic => "Semantic",
YLayer::Reasoning => "Reasoning",
YLayer::Experience => "Experience",
YLayer::Journal => "Journal",
YLayer::Procedural => "Procedural",
YLayer::Metacognitive => "Metacognitive",
}
}
}
impl fmt::Display for YLayer {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Y{}: {}", self.as_u8(), self.name())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_layer_roundtrip() {
for layer in YLayer::ALL {
let v = layer.as_u8();
let parsed = YLayer::from_u8(v).unwrap();
assert_eq!(layer, parsed);
}
}
#[test]
fn test_definitional_experiential_split() {
for layer in YLayer::DEFINITIONAL {
assert!(layer.is_definitional());
assert!(!layer.is_experiential());
}
for layer in YLayer::EXPERIENTIAL {
assert!(layer.is_experiential());
assert!(!layer.is_definitional());
}
}
#[test]
fn test_invalid_layer() {
assert_eq!(YLayer::from_u8(7), None);
assert_eq!(YLayer::from_u8(255), None);
}
}