Use the generate_attribute macro in muc::user
This commit is contained in:
parent
27cf9a6298
commit
98878042dd
1 changed files with 13 additions and 69 deletions
|
@ -278,76 +278,20 @@ impl IntoElements for Reason {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
generate_attribute!(Affiliation, "affiliation", {
|
||||||
pub enum Affiliation {
|
Owner => "owner",
|
||||||
Owner,
|
Admin => "admin",
|
||||||
Admin,
|
Member => "member",
|
||||||
Member,
|
Outcast => "outcast",
|
||||||
Outcast,
|
None => "none",
|
||||||
None,
|
}, Default = None);
|
||||||
}
|
|
||||||
|
|
||||||
impl FromStr for Affiliation {
|
generate_attribute!(Role, "role", {
|
||||||
type Err = Error;
|
Moderator => "moderator",
|
||||||
|
Participant => "participant",
|
||||||
fn from_str(s: &str) -> Result<Affiliation, Error> {
|
Visitor => "visitor",
|
||||||
Ok(match s {
|
None => "none",
|
||||||
"owner" => Affiliation::Owner,
|
}, Default = None);
|
||||||
"admin" => Affiliation::Admin,
|
|
||||||
"member" => Affiliation::Member,
|
|
||||||
"outcast" => Affiliation::Outcast,
|
|
||||||
"none" => Affiliation::None,
|
|
||||||
|
|
||||||
_ => return Err(Error::ParseError("Unknown affiliation.")),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoAttributeValue for Affiliation {
|
|
||||||
fn into_attribute_value(self) -> Option<String> {
|
|
||||||
Some(String::from(match self {
|
|
||||||
Affiliation::Owner => "owner",
|
|
||||||
Affiliation::Admin => "admin",
|
|
||||||
Affiliation::Member => "member",
|
|
||||||
Affiliation::Outcast => "outcast",
|
|
||||||
Affiliation::None => "none",
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
|
||||||
pub enum Role {
|
|
||||||
Moderator,
|
|
||||||
Participant,
|
|
||||||
Visitor,
|
|
||||||
None,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromStr for Role {
|
|
||||||
type Err = Error;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Role, Error> {
|
|
||||||
Ok(match s {
|
|
||||||
"moderator" => Role::Moderator,
|
|
||||||
"participant" => Role::Participant,
|
|
||||||
"visitor" => Role::Visitor,
|
|
||||||
"none" => Role::None,
|
|
||||||
|
|
||||||
_ => return Err(Error::ParseError("Unknown role.")),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoAttributeValue for Role {
|
|
||||||
fn into_attribute_value(self) -> Option<String> {
|
|
||||||
Some(String::from(match self {
|
|
||||||
Role::Moderator => "moderator",
|
|
||||||
Role::Participant => "participant",
|
|
||||||
Role::Visitor => "visitor",
|
|
||||||
Role::None => "none",
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Item {
|
pub struct Item {
|
||||||
|
|
Loading…
Reference in a new issue