use crate::ValueKind;
#[doc = crate::_tags!(data value)]
#[doc = crate::_doc_meta!{location("data/value")}]
#[repr(u8)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum ValueKind4 {
#[default]
Nil = 0,
Bool = 1,
Int = 2,
UInt = 3,
Float = 4,
Char = 5,
Symbol = 6,
Enum = 7,
Ref = 8,
Bytes = 9,
Text = 10,
List = 11,
Set = 12,
Table = 13,
Callable = 14,
Escape = 15,
}
impl ValueKind4 {
#[must_use]
#[inline(always)]
pub const fn code(self) -> u8 {
self as u8
}
#[must_use]
#[inline(always)]
pub const fn from_code(code: u8) -> Option<Self> {
match code {
0 => Some(Self::Nil),
1 => Some(Self::Bool),
2 => Some(Self::Int),
3 => Some(Self::UInt),
4 => Some(Self::Float),
5 => Some(Self::Char),
6 => Some(Self::Symbol),
7 => Some(Self::Enum),
8 => Some(Self::Ref),
9 => Some(Self::Bytes),
10 => Some(Self::Text),
11 => Some(Self::List),
12 => Some(Self::Set),
13 => Some(Self::Table),
14 => Some(Self::Callable),
15 => Some(Self::Escape),
_ => None,
}
}
#[must_use]
#[inline(always)]
pub const fn to_kind(self) -> ValueKind {
ValueKind::from_code(self.code())
}
#[must_use]
#[inline(always)]
pub const fn from_kind(kind: ValueKind) -> Option<Self> {
if kind.is_compact() { Self::from_code(kind.code()) } else { None }
}
}