use std::fmt;
use serde_json::Value;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum JsonTopLevelKind {
Object,
Array,
Other,
}
impl JsonTopLevelKind {
#[inline]
#[must_use]
pub fn of(value: &Value) -> Self {
match value {
Value::Object(_) => Self::Object,
Value::Array(_) => Self::Array,
_ => Self::Other,
}
}
}
impl From<&Value> for JsonTopLevelKind {
#[inline]
fn from(value: &Value) -> Self {
Self::of(value)
}
}
impl fmt::Display for JsonTopLevelKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let text = match self {
Self::Object => "object",
Self::Array => "array",
Self::Other => "other",
};
f.write_str(text)
}
}