create IntoContent trait and add Comment ContentBuilder type
This commit is contained in:
parent
547e7c6a30
commit
692a9ebce8
|
@ -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())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue