use std::collections::hash_map::DefaultHasher;
use std::collections::HashMap;
use std::fmt;
mod blob;
mod comment;
mod text;
mod value;
pub use self::blob::Blob;
pub use self::comment::Comment;
pub use self::text::Text;
pub use self::value::Value;
pub type Attributes = HashMap<String, Value>;
pub type Children = Vec<Box<dyn Node>>;
pub trait Node:
'static + fmt::Debug + fmt::Display + NodeClone + NodeDefaultHash + Send + Sync
{
#[inline]
fn append<T>(&mut self, _: T)
where
Self: Sized,
T: Into<Box<dyn Node>>,
{
}
#[inline]
fn assign<T, U>(&mut self, _: T, _: U)
where
Self: Sized,
T: Into<String>,
U: Into<Value>,
{
}
fn get_name(&self) -> &str;
#[inline]
fn get_attributes(&self) -> Option<&Attributes> {
None
}
fn get_attributes_mut(&mut self) -> Option<&mut Attributes> {
None
}
fn get_children(&self) -> Option<&Children> {
None
}
fn get_children_mut(&mut self) -> Option<&mut Children> {
None
}
#[doc(hidden)]
fn is_bare(&self) -> bool {
false
}
#[doc(hidden)]
fn is_bareable(&self) -> bool {
false
}
}
#[doc(hidden)]
pub trait NodeClone {
fn clone(&self) -> Box<dyn Node>;
}
#[doc(hidden)]
pub trait NodeDefaultHash {
fn default_hash(&self, state: &mut DefaultHasher);
}
impl<T> NodeClone for T
where
T: Node + Clone,
{
#[inline]
fn clone(&self) -> Box<dyn Node> {
Box::new(Clone::clone(self))
}
}
impl Clone for Box<dyn Node> {
#[inline]
fn clone(&self) -> Self {
NodeClone::clone(&**self)
}
}
impl<T> From<T> for Box<dyn Node>
where
T: Node,
{
#[inline]
fn from(node: T) -> Box<dyn Node> {
Box::new(node)
}
}
impl NodeDefaultHash for Box<dyn Node> {
#[inline]
fn default_hash(&self, state: &mut DefaultHasher) {
NodeDefaultHash::default_hash(&**self, state)
}
}
pub mod element;