diff options
| author | 2024-12-04 02:09:07 +0000 | |
|---|---|---|
| committer | 2024-12-04 02:09:07 +0000 | |
| commit | 4886396044356d2676a77c3900af796fe7641f42 (patch) | |
| tree | 685c67b7db0f22a7262fc6431d7849d63c510e66 /src/stanza | |
| parent | e0373c0520e7fae792bc907e9c500ab846d34e31 (diff) | |
| download | luz-4886396044356d2676a77c3900af796fe7641f42.tar.gz luz-4886396044356d2676a77c3900af796fe7641f42.tar.bz2 luz-4886396044356d2676a77c3900af796fe7641f42.zip | |
implement client
Diffstat (limited to 'src/stanza')
| -rw-r--r-- | src/stanza/client/mod.rs | 27 | 
1 files changed, 20 insertions, 7 deletions
| diff --git a/src/stanza/client/mod.rs b/src/stanza/client/mod.rs index 25d7b56..2b063d6 100644 --- a/src/stanza/client/mod.rs +++ b/src/stanza/client/mod.rs @@ -1,7 +1,7 @@  use iq::Iq;  use message::Message;  use peanuts::{ -    element::{FromElement, IntoElement}, +    element::{Content, ContentBuilder, FromContent, FromElement, IntoContent, IntoElement},      DeserializeError,  };  use presence::Presence; @@ -20,6 +20,18 @@ pub enum Stanza {      Presence(Presence),      Iq(Iq),      Error(StreamError), +    OtherContent(Content), +} + +impl FromContent for Stanza { +    fn from_content(content: Content) -> peanuts::element::DeserializeResult<Self> { +        match content { +            Content::Element(element) => Ok(Stanza::from_element(element)?), +            Content::Text(_) => Ok(Stanza::OtherContent(content)), +            Content::PI => Ok(Stanza::OtherContent(content)), +            Content::Comment(_) => Ok(Stanza::OtherContent(content)), +        } +    }  }  impl FromElement for Stanza { @@ -36,13 +48,14 @@ impl FromElement for Stanza {      }  } -impl IntoElement for Stanza { -    fn builder(&self) -> peanuts::element::ElementBuilder { +impl IntoContent for Stanza { +    fn builder(&self) -> peanuts::element::ContentBuilder {          match self { -            Stanza::Message(message) => message.builder(), -            Stanza::Presence(presence) => presence.builder(), -            Stanza::Iq(iq) => iq.builder(), -            Stanza::Error(error) => error.builder(), +            Stanza::Message(message) => <Message as IntoContent>::builder(message), +            Stanza::Presence(presence) => <Presence as IntoContent>::builder(presence), +            Stanza::Iq(iq) => <Iq as IntoContent>::builder(iq), +            Stanza::Error(error) => <StreamError as IntoContent>::builder(error), +            Stanza::OtherContent(_content) => ContentBuilder::Comment("other-content".to_string()),          }      }  } | 
