1 use std::collections::hash_map::DefaultHasher; 2 use std::fmt; 3 use std::hash::Hash; 4 5 use crate::node::{Node, Value}; 6 7 /// A text node. 8 #[derive(Clone, Debug)] 9 pub struct Text { 10 content: String, 11 } 12 13 impl Text { 14 /// Create a node. 15 #[inline] new<T>(content: T) -> Self where T: Into<String>,16 pub fn new<T>(content: T) -> Self 17 where 18 T: Into<String>, 19 { 20 Text { 21 content: content.into(), 22 } 23 } 24 } 25 26 impl fmt::Display for Text { 27 #[inline] fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result28 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { 29 self.content.fmt(formatter) 30 } 31 } 32 33 impl Node for Text { 34 #[inline] append<T>(&mut self, _: T) where T: Node,35 fn append<T>(&mut self, _: T) 36 where 37 T: Node, 38 { 39 } 40 41 #[inline] assign<T, U>(&mut self, _: T, _: U) where T: Into<String>, U: Into<Value>,42 fn assign<T, U>(&mut self, _: T, _: U) 43 where 44 T: Into<String>, 45 U: Into<Value>, 46 { 47 } 48 } 49 50 impl super::NodeDefaultHash for Text { 51 #[inline] default_hash(&self, state: &mut DefaultHasher)52 fn default_hash(&self, state: &mut DefaultHasher) { 53 self.content.hash(state); 54 } 55 } 56