From 98878042dd4ba1a630f85b329645527f59093b9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Tue, 27 Jun 2017 00:14:40 +0100 Subject: [PATCH] Use the generate_attribute macro in muc::user --- src/muc/user.rs | 82 ++++++++----------------------------------------- 1 file changed, 13 insertions(+), 69 deletions(-) diff --git a/src/muc/user.rs b/src/muc/user.rs index 8dae704..833b560 100644 --- a/src/muc/user.rs +++ b/src/muc/user.rs @@ -278,76 +278,20 @@ impl IntoElements for Reason { } } -#[derive(Debug, Clone, PartialEq)] -pub enum Affiliation { - Owner, - Admin, - Member, - Outcast, - None, -} +generate_attribute!(Affiliation, "affiliation", { + Owner => "owner", + Admin => "admin", + Member => "member", + Outcast => "outcast", + None => "none", +}, Default = None); -impl FromStr for Affiliation { - type Err = Error; - - fn from_str(s: &str) -> Result { - Ok(match s { - "owner" => Affiliation::Owner, - "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 { - 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 { - 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 { - Some(String::from(match self { - Role::Moderator => "moderator", - Role::Participant => "participant", - Role::Visitor => "visitor", - Role::None => "none", - })) - } -} +generate_attribute!(Role, "role", { + Moderator => "moderator", + Participant => "participant", + Visitor => "visitor", + None => "none", +}, Default = None); #[derive(Debug, Clone)] pub struct Item {