diff options
author | 2024-11-24 02:05:41 +0000 | |
---|---|---|
committer | 2024-11-24 02:05:41 +0000 | |
commit | 87e6ff405b0d687ed341f304fba7c5b391a49359 (patch) | |
tree | f56ddd5271fb2bb104f641c035e58a744038f5cf /src/element.rs | |
parent | c1e6f7e918eacaad9c8b1a4b27fcd4d6245aaf68 (diff) | |
download | peanuts-87e6ff405b0d687ed341f304fba7c5b391a49359.tar.gz peanuts-87e6ff405b0d687ed341f304fba7c5b391a49359.tar.bz2 peanuts-87e6ff405b0d687ed341f304fba7c5b391a49359.zip |
misc
Diffstat (limited to 'src/element.rs')
-rw-r--r-- | src/element.rs | 19 |
1 files changed, 17 insertions, 2 deletions
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<Self>; +} + +pub trait IntoElement { + fn into_element(&self) -> Element; + + fn get_content(&self) -> Vec<Content> { + 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<Name, String>, + // TODO: make a hashmap maybe? to be able to address parts of the content individually pub content: Vec<Content>, } |