-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters