From 87e6ff405b0d687ed341f304fba7c5b391a49359 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Sun, 24 Nov 2024 02:05:41 +0000 Subject: misc --- src/element.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/element.rs') diff --git a/src/element.rs b/src/element.rs index 04f2e5e..2b149a8 100644 --- a/src/element.rs +++ b/src/element.rs @@ -9,8 +9,22 @@ use std::{ use crate::{ error::Error, xml::{self, parsers_complete::Parser, Attribute}, + Result, }; +pub trait FromElement: Sized { + fn from_element(element: Element) -> Result; +} + +pub trait IntoElement { + fn into_element(&self) -> Element; + + fn get_content(&self) -> Vec { + let element = self.into_element(); + element.content + } +} + // when are namespaces names chosen then if they are automatically calculated // namespaces are held by readers and writers. #[derive(PartialEq, Eq, Hash, Clone, Debug)] @@ -26,7 +40,7 @@ pub struct Name { pub local_name: String, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub enum Content { Element(Element), Text(String), @@ -35,7 +49,7 @@ pub enum Content { } // should this be a trait? -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Element { pub name: Name, // namespace: Name, @@ -51,6 +65,7 @@ pub struct Element { // you can validate the prefix and calculate the namespace from the current reader context // this results in readers and writers being able to return qualification errors as they aren't able to create elements until every part is qualified. pub attributes: HashMap, + // TODO: make a hashmap maybe? to be able to address parts of the content individually pub content: Vec, } -- cgit