summaryrefslogtreecommitdiffstats
path: root/src/stanza/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/stanza/mod.rs46
1 files changed, 30 insertions, 16 deletions
diff --git a/src/stanza/mod.rs b/src/stanza/mod.rs
index c29b1a2..ad9e228 100644
--- a/src/stanza/mod.rs
+++ b/src/stanza/mod.rs
@@ -1,5 +1,7 @@
// use quick_xml::events::BytesDecl;
+pub mod bind;
+pub mod iq;
pub mod sasl;
pub mod stream;
@@ -128,28 +130,40 @@ impl<'e> Element<'e> {
e => Err(ElementError::NotAStart(e.into_owned()).into()),
}
}
-}
-/// if there is only one child in the vec of children, will return that element
-pub fn child<'p, 'e>(element: &'p Element<'e>) -> Result<&'p Element<'e>, ElementError<'static>> {
- if let Some(children) = &element.children {
- if children.len() == 1 {
- return Ok(&children[0]);
- } else {
- return Err(ElementError::MultipleChildren);
+ /// if there is only one child in the vec of children, will return that element
+ pub fn child<'p>(&'p self) -> Result<&'p Element<'e>, ElementError<'static>> {
+ if let Some(children) = &self.children {
+ if children.len() == 1 {
+ return Ok(&children[0]);
+ } else {
+ return Err(ElementError::MultipleChildren);
+ }
+ }
+ Err(ElementError::NoChildren)
+ }
+
+ /// returns reference to children
+ pub fn children<'p>(&'p self) -> Result<&'p Vec<Element<'e>>, ElementError<'e>> {
+ if let Some(children) = &self.children {
+ return Ok(children);
}
+ Err(ElementError::NoChildren)
}
- Err(ElementError::NoChildren)
}
-/// returns reference to children
-pub fn children<'p, 'e>(
- element: &'p Element<'e>,
-) -> Result<&'p Vec<Element<'e>>, ElementError<'e>> {
- if let Some(children) = &element.children {
- return Ok(children);
+pub trait IntoElement<'e> {
+ fn event(&self) -> Event<'e>;
+ fn children(&self) -> Option<Vec<Element<'e>>>;
+}
+
+impl<'e, T: IntoElement<'e>> From<T> for Element<'e> {
+ fn from(value: T) -> Self {
+ Element {
+ event: value.event(),
+ children: value.children(),
+ }
}
- Err(ElementError::NoChildren)
}
#[derive(Debug)]