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)]
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())),
}
}
}