#[cfg(feature = "std")]
use std::collections::HashMap;
#[cfg(not(feature = "std"))]
use alloc::{collections::BTreeMap as HashMap, string::String, vec::Vec};
use smallvec::SmallVec;
pub use babbel_core::num::Numeric;
#[derive(Clone, Debug, PartialEq)]
pub enum Node {
Boolean(bool),
Number(Numeric),
Str(String),
Array(Vec<Node>),
Object(HashMap<String, Node>),
None,
}
impl Node {
pub fn from_iter<I: IntoIterator<Item = Node>>(iter: I) -> Self {
let mut small: SmallVec<[Node; 8]> = SmallVec::new();
for item in iter {
small.push(item);
}
Node::Array(small.into_vec())
}
pub fn from_slice(slice: &[Node]) -> Self {
Node::Array(slice.to_vec())
}
pub fn from_vec(vec: Vec<Node>) -> Self {
Node::Array(vec)
}
pub fn new_object() -> Self {
Node::Object(HashMap::new())
}
pub fn new_array() -> Self {
Node::Array(Vec::new())
}
}