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