diff --git a/src/node/blob.rs b/src/node/blob.rs new file mode 100644 index 0000000..6ab2792 --- /dev/null +++ b/src/node/blob.rs @@ -0,0 +1,55 @@ +use std::collections::hash_map::DefaultHasher; +use std::fmt; +use std::hash::Hash; + +use crate::node::{Node, Value}; + +/// A blob node. +#[derive(Clone, Debug)] +pub struct Blob { + content: String, +} + +impl Blob { + /// Create a node. + #[inline] + pub fn new(content: T) -> Self + where + T: Into, + { + Blob { + content: content.into(), + } + } +} + +impl fmt::Display for Blob { + #[inline] + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + self.content.fmt(formatter) + } +} + +impl Node for Blob { + #[inline] + fn append(&mut self, _: T) + where + T: Into>, + { + } + + #[inline] + fn assign(&mut self, _: T, _: U) + where + T: Into, + U: Into, + { + } +} + +impl super::NodeDefaultHash for Blob { + #[inline] + fn default_hash(&self, state: &mut DefaultHasher) { + self.content.hash(state); + } +} diff --git a/src/node/mod.rs b/src/node/mod.rs index cef65c6..6f221b4 100644 --- a/src/node/mod.rs +++ b/src/node/mod.rs @@ -4,10 +4,12 @@ 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;