iq: Add helper constructors.
This commit is contained in:
parent
d29021b85c
commit
d5f88d2636
1 changed files with 53 additions and 0 deletions
53
src/iq.rs
53
src/iq.rs
|
@ -55,6 +55,59 @@ pub struct Iq {
|
||||||
pub payload: IqType,
|
pub payload: IqType,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Iq {
|
||||||
|
pub fn from_get(payload: impl IqGetPayload) -> Iq {
|
||||||
|
Iq {
|
||||||
|
from: None,
|
||||||
|
to: None,
|
||||||
|
id: None,
|
||||||
|
payload: IqType::Get(payload.into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_set(payload: impl IqSetPayload) -> Iq {
|
||||||
|
Iq {
|
||||||
|
from: None,
|
||||||
|
to: None,
|
||||||
|
id: None,
|
||||||
|
payload: IqType::Set(payload.into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_result(payload: Option<impl IqResultPayload>) -> Iq {
|
||||||
|
Iq {
|
||||||
|
from: None,
|
||||||
|
to: None,
|
||||||
|
id: None,
|
||||||
|
payload: IqType::Result(payload.map(|payload| payload.into())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_error(payload: StanzaError) -> Iq {
|
||||||
|
Iq {
|
||||||
|
from: None,
|
||||||
|
to: None,
|
||||||
|
id: None,
|
||||||
|
payload: IqType::Error(payload),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_to(mut self, to: Jid) -> Iq {
|
||||||
|
self.to = Some(to);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_from(mut self, from: Jid) -> Iq {
|
||||||
|
self.from = Some(from);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_id(mut self, id: String) -> Iq {
|
||||||
|
self.id = Some(id);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl TryFrom<Element> for Iq {
|
impl TryFrom<Element> for Iq {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue