aboutsummaryrefslogtreecommitdiffstats
path: root/src/element.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/element.rs')
-rw-r--r--src/element.rs19
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>,
}