mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
muc/user: Generate Reason automatically.
This commit is contained in:
parent
5a2f4859cf
commit
32f427a73c
1 changed files with 1 additions and 28 deletions
|
@ -196,34 +196,7 @@ generate_element_with_only_attributes!(Continue, "continue", ns::MUC_USER, [
|
||||||
thread: Option<String> = "thread" => optional,
|
thread: Option<String> = "thread" => optional,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
generate_elem_id!(Reason, "reason", ns::MUC_USER);
|
||||||
pub struct Reason(String);
|
|
||||||
|
|
||||||
impl TryFrom<Element> for Reason {
|
|
||||||
type Err = Error;
|
|
||||||
|
|
||||||
fn try_from(elem: Element) -> Result<Reason, Error> {
|
|
||||||
if !elem.is("reason", ns::MUC_USER) {
|
|
||||||
return Err(Error::ParseError("This is not a reason element."));
|
|
||||||
}
|
|
||||||
for _ in elem.children() {
|
|
||||||
return Err(Error::ParseError("Unknown child in reason element."));
|
|
||||||
}
|
|
||||||
for _ in elem.attrs() {
|
|
||||||
return Err(Error::ParseError("Unknown attribute in reason element."));
|
|
||||||
}
|
|
||||||
Ok(Reason(elem.text()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Reason> for Element {
|
|
||||||
fn from(reason: Reason) -> Element {
|
|
||||||
Element::builder("reason")
|
|
||||||
.ns(ns::MUC_USER)
|
|
||||||
.append(reason.0)
|
|
||||||
.build()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
generate_attribute!(Affiliation, "affiliation", {
|
generate_attribute!(Affiliation, "affiliation", {
|
||||||
Owner => "owner",
|
Owner => "owner",
|
||||||
|
|
Loading…
Reference in a new issue