use indexmap::IndexMap;
use crate::temporal::TemporalValue;
pub type Object = IndexMap<String, Value>;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq)]
pub enum Value {
Null,
Bool(bool),
I64(i64),
U64(u64),
F64(f64),
String(String),
Temporal(TemporalValue),
Bytes(Vec<u8>),
Array(Vec<Value>),
Object(Object),
}
impl Value {
pub(crate) fn is_scalar(&self) -> bool {
matches!(
self,
Self::Null
| Self::Bool(_)
| Self::I64(_)
| Self::U64(_)
| Self::F64(_)
| Self::String(_)
| Self::Temporal(_)
| Self::Bytes(_)
)
}
pub(crate) fn is_empty_for_decode(&self) -> bool {
match self {
Self::Null => true,
Self::String(text) => text.is_empty(),
Self::Array(values) => values.is_empty(),
Self::Object(entries) => entries.is_empty(),
_ => false,
}
}
}
impl From<Object> for Value {
fn from(value: Object) -> Self {
Self::Object(value)
}
}
#[cfg(test)]
mod tests;