diff --git a/src/iq.rs b/src/iq.rs index 49bdc9b7e62bcdf82edd4ed057fa5ac40b4f0993..aeeb836cc112ef5904d0196a911fc362038046b3 100644 --- a/src/iq.rs +++ b/src/iq.rs @@ -5,8 +5,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -#![allow(missing_docs)] - use try_from::TryFrom; use minidom::Element; @@ -29,11 +27,19 @@ pub trait IqSetPayload: TryFrom + Into {} /// Should be implemented on every known payload of an ``. pub trait IqResultPayload: TryFrom + Into {} +/// Represents one of the four possible iq types. #[derive(Debug, Clone)] pub enum IqType { + /// This is a request for accessing some data. Get(Element), + + /// This is a request for modifying some data. Set(Element), + + /// This is a result containing some data. Result(Option), + + /// A get or set request failed. Error(StanzaError), } @@ -51,13 +57,22 @@ impl<'a> IntoAttributeValue for &'a IqType { /// The main structure representing the `` stanza. #[derive(Debug, Clone)] pub struct Iq { + /// The JID emitting this stanza. pub from: Option, + + /// The recipient of this stanza. pub to: Option, + + /// The @id attribute of this stanza, which is required in order to match a + /// request with its result/error. pub id: Option, + + /// The payload content of this stanza. pub payload: IqType, } impl Iq { + /// Creates an `` stanza containing a get request. pub fn from_get(payload: impl IqGetPayload) -> Iq { Iq { from: None, @@ -67,6 +82,7 @@ impl Iq { } } + /// Creates an `` stanza containing a set request. pub fn from_set(payload: impl IqSetPayload) -> Iq { Iq { from: None, @@ -76,6 +92,7 @@ impl Iq { } } + /// Creates an `` stanza containing a result. pub fn from_result(payload: Option) -> Iq { Iq { from: None, @@ -85,6 +102,7 @@ impl Iq { } } + /// Creates an `` stanza containing an error. pub fn from_error(payload: StanzaError) -> Iq { Iq { from: None, @@ -94,16 +112,19 @@ impl Iq { } } + /// Sets the recipient of this stanza. pub fn with_to(mut self, to: Jid) -> Iq { self.to = Some(to); self } + /// Sets the emitter of this stanza. pub fn with_from(mut self, from: Jid) -> Iq { self.from = Some(from); self } + /// Sets the id of this stanza, in order to later match its response. pub fn with_id(mut self, id: String) -> Iq { self.id = Some(id); self