aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2024-12-04 02:35:42 +0000
committerLibravatar cel 🌸 <cel@bunny.garden>2024-12-04 02:35:42 +0000
commit692a9ebce8eb37bbcd360a100a4c1395fa803e61 (patch)
treed48a2b527cd318c71cc7d043e275b41e357701c0
parent547e7c6a304822914816efc5a0a8b386bc358296 (diff)
downloadpeanuts-692a9ebce8eb37bbcd360a100a4c1395fa803e61.tar.gz
peanuts-692a9ebce8eb37bbcd360a100a4c1395fa803e61.tar.bz2
peanuts-692a9ebce8eb37bbcd360a100a4c1395fa803e61.zip
create IntoContent trait and add Comment ContentBuilder type
-rw-r--r--src/element.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/element.rs b/src/element.rs
index 3f4bee3..48d4d90 100644
--- a/src/element.rs
+++ b/src/element.rs
@@ -3,7 +3,7 @@
#![feature(drain_filter)]
use std::{
- collections::{HashMap, HashSet, VecDeque},
+ collections::{vec_deque, HashMap, HashSet, VecDeque},
convert::Infallible,
str::FromStr,
};
@@ -580,6 +580,10 @@ impl ElementBuilder {
}
pub trait IntoContent {
+ fn into_content(&self) -> Content {
+ self.builder().build().unwrap()
+ }
+
fn builder(&self) -> ContentBuilder;
}
@@ -592,9 +596,14 @@ where
}
}
+pub trait FromContent: Sized {
+ fn from_content(content: Content) -> DeserializeResult<Self>;
+}
+
pub enum ContentBuilder {
Element(ElementBuilder),
Text(String),
+ Comment(String),
}
impl ContentBuilder {
@@ -604,6 +613,7 @@ impl ContentBuilder {
Ok(Content::Element(element_builder.build()?))
}
ContentBuilder::Text(text) => Ok(Content::Text(text.to_string())),
+ ContentBuilder::Comment(s) => Ok(Content::Comment(s.to_string())),
}
}
}