From 692a9ebce8eb37bbcd360a100a4c1395fa803e61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cel=20=F0=9F=8C=B8?= Date: Wed, 4 Dec 2024 02:35:42 +0000 Subject: [PATCH] create IntoContent trait and add Comment ContentBuilder type --- src/element.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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; +} + 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())), } } }