diff options
author | cel 🌸 <cel@blos.sm> | 2023-08-02 00:56:38 +0100 |
---|---|---|
committer | cel 🌸 <cel@blos.sm> | 2023-08-02 00:56:38 +0100 |
commit | cd7bb95c0a31d187bfe25bad15043f0b33b111cf (patch) | |
tree | c5be0c651198abf736f8867a36906f9345f3a0ac /src/stanza/mod.rs | |
parent | 322b2a3b46348ec1c5acbc538de93310c9030b96 (diff) | |
download | luz-cd7bb95c0a31d187bfe25bad15043f0b33b111cf.tar.gz luz-cd7bb95c0a31d187bfe25bad15043f0b33b111cf.tar.bz2 luz-cd7bb95c0a31d187bfe25bad15043f0b33b111cf.zip |
implement resource binding
Diffstat (limited to 'src/stanza/mod.rs')
-rw-r--r-- | src/stanza/mod.rs | 46 |
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)] |