#[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 ValueKind {
#[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,
Object = 32,
Resource = 33,
Temporal = 34,
Color = 35,
Pair = 36,
Unknown = 255,
}
impl ValueKind {
#[must_use]
#[inline(always)]
pub const fn code(self) -> u8 {
self as u8
}
#[must_use]
#[inline(always)]
pub const fn from_code(code: u8) -> Self {
match code {
0 => Self::Nil,
1 => Self::Bool,
2 => Self::Int,
3 => Self::UInt,
4 => Self::Float,
5 => Self::Char,
6 => Self::Symbol,
7 => Self::Enum,
8 => Self::Ref,
9 => Self::Bytes,
10 => Self::Text,
11 => Self::List,
12 => Self::Set,
13 => Self::Table,
14 => Self::Callable,
15 => Self::Escape,
32 => Self::Object,
33 => Self::Resource,
34 => Self::Temporal,
35 => Self::Color,
36 => Self::Pair,
255 => Self::Unknown,
_ => Self::Unknown,
}
}
}
impl ValueKind {
#[must_use]
#[inline(always)]
pub const fn is_compact(self) -> bool {
self.code() <= 15
}
#[must_use]
#[inline(always)]
pub const fn is_nil(self) -> bool {
matches!(self, Self::Nil)
}
#[must_use]
#[inline(always)]
pub const fn is_number(self) -> bool {
matches!(self, Self::Int | Self::UInt | Self::Float)
}
#[must_use]
#[inline(always)]
pub const fn is_scalar(self) -> bool {
matches!(
self,
Self::Nil
| Self::Bool
| Self::Int
| Self::UInt
| Self::Float
| Self::Char
| Self::Symbol
| Self::Enum
)
}
#[must_use]
#[inline(always)]
pub const fn is_ref_like(self) -> bool {
matches!(self, Self::Ref)
}
#[must_use]
#[inline(always)]
pub const fn is_aggregate(self) -> bool {
matches!(self, Self::Bytes | Self::Set | Self::Text | Self::List | Self::Table)
}
#[must_use]
#[inline(always)]
pub const fn is_callable(self) -> bool {
matches!(self, Self::Callable)
}
#[must_use]
#[inline(always)]
pub const fn is_object(self) -> bool {
matches!(self, Self::Object)
}
#[must_use]
#[inline(always)]
pub const fn is_resource(self) -> bool {
matches!(self, Self::Resource)
}
#[must_use]
#[inline(always)]
pub const fn is_escape(self) -> bool {
matches!(self, Self::Escape)
}
#[must_use]
#[inline(always)]
pub const fn is_unknown(self) -> bool {
matches!(self, Self::Unknown)
}
}