Skip to content

Commit

Permalink
add blob node
Browse files Browse the repository at this point in the history
  • Loading branch information
flxzt committed Feb 16, 2024
1 parent c56acee commit 6eb41e9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/node/blob.rs
Original file line number Diff line number Diff line change
@@ -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<T>(content: T) -> Self
where
T: Into<String>,
{
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<T>(&mut self, _: T)
where
T: Into<Box<dyn Node>>,
{
}

#[inline]
fn assign<T, U>(&mut self, _: T, _: U)
where
T: Into<String>,
U: Into<Value>,
{
}
}

impl super::NodeDefaultHash for Blob {
#[inline]
fn default_hash(&self, state: &mut DefaultHasher) {
self.content.hash(state);
}
}
2 changes: 2 additions & 0 deletions src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6eb41e9

Please sign in to comment.