use super::*;
use crate::schema::MessyJsonObjectTrait;
pub type KeyType = ArcStr;
#[derive(Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct MessyJsonObject(Arc<MessyJsonObjectInner>);
impl MessyJsonObject {
#[inline]
pub fn builder(&self, settings: MessyJsonSettings) -> MessyJsonObjectBuilder {
MessyJsonObjectBuilder::new(self, settings)
}
}
impl std::ops::Deref for MessyJsonObject {
type Target = MessyJsonObjectInner;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl From<MessyJsonObjectInner> for MessyJsonObject {
fn from(x: MessyJsonObjectInner) -> Self {
MessyJsonObject(Arc::new(x))
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct MessyJsonObjectInner {
optional: bool,
properties: BTreeMap<KeyType, MessyJson>,
}
impl MessyJsonObjectInner {
pub fn new(properties: BTreeMap<KeyType, MessyJson>, optional: bool) -> Self {
MessyJsonObjectInner {
properties: properties.into_iter().collect(),
optional,
}
}
#[inline]
pub fn properties(&self) -> &BTreeMap<KeyType, MessyJson> {
&self.properties
}
#[inline]
pub fn has_field(&self, key: &str) -> bool {
self.properties.contains_key(key)
}
#[inline]
pub fn optional(&self) -> bool {
self.optional
}
}
#[cfg(test)]
pub fn gen_key(k: &str) -> super::object::KeyType {
ArcStr::from(k)
}