create IntoContent trait and add Comment ContentBuilder type

This commit is contained in:
cel 🌸 2024-12-04 02:35:42 +00:00
parent 547e7c6a30
commit 692a9ebce8
1 changed files with 11 additions and 1 deletions

View File

@ -3,7 +3,7 @@
#![feature(drain_filter)] #![feature(drain_filter)]
use std::{ use std::{
collections::{HashMap, HashSet, VecDeque}, collections::{vec_deque, HashMap, HashSet, VecDeque},
convert::Infallible, convert::Infallible,
str::FromStr, str::FromStr,
}; };
@ -580,6 +580,10 @@ impl ElementBuilder {
} }
pub trait IntoContent { pub trait IntoContent {
fn into_content(&self) -> Content {
self.builder().build().unwrap()
}
fn builder(&self) -> ContentBuilder; fn builder(&self) -> ContentBuilder;
} }
@ -592,9 +596,14 @@ where
} }
} }
pub trait FromContent: Sized {
fn from_content(content: Content) -> DeserializeResult<Self>;
}
pub enum ContentBuilder { pub enum ContentBuilder {
Element(ElementBuilder), Element(ElementBuilder),
Text(String), Text(String),
Comment(String),
} }
impl ContentBuilder { impl ContentBuilder {
@ -604,6 +613,7 @@ impl ContentBuilder {
Ok(Content::Element(element_builder.build()?)) Ok(Content::Element(element_builder.build()?))
} }
ContentBuilder::Text(text) => Ok(Content::Text(text.to_string())), ContentBuilder::Text(text) => Ok(Content::Text(text.to_string())),
ContentBuilder::Comment(s) => Ok(Content::Comment(s.to_string())),
} }
} }
} }