From 33018a5c09a231524647ea7529fea320b6c88bdd Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 10 Oct 2017 17:40:29 +0100 Subject: [PATCH] =?UTF-8?q?roster:=20Make=20subscription=3D"none"=20the=20?= =?UTF-8?q?default,=20see=20RFC6121=20=C2=A72.1.2.5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/roster.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/roster.rs b/src/roster.rs index ae26c3d..38b183f 100644 --- a/src/roster.rs +++ b/src/roster.rs @@ -21,7 +21,7 @@ generate_attribute!(Subscription, "subscription", { To => "to", Both => "both", Remove => "remove", -}); +}, Default = None); /// Contact from the user’s contact list. #[derive(Debug, Clone, PartialEq)] @@ -33,7 +33,7 @@ pub struct Item { pub name: Option, /// Subscription status of this contact. - pub subscription: Option, + pub subscription: Subscription, /// Groups this contact is part of. pub groups: Vec, @@ -50,7 +50,7 @@ impl TryFrom for Item { let mut item = Item { jid: get_attr!(elem, "jid", required), name: get_attr!(elem, "name", optional).and_then(|name| if name == "" { None } else { Some(name) }), - subscription: get_attr!(elem, "subscription", optional), + subscription: get_attr!(elem, "subscription", default), groups: vec!(), }; for child in elem.children() { @@ -183,7 +183,7 @@ mod tests { assert_eq!(roster.items.len(), 3); assert_eq!(roster.items[0].jid, Jid::from_str("romeo@example.net").unwrap()); assert_eq!(roster.items[0].name, Some(String::from("Romeo"))); - assert_eq!(roster.items[0].subscription, Some(Subscription::Both)); + assert_eq!(roster.items[0].subscription, Subscription::Both); assert_eq!(roster.items[0].groups, vec!(Group::from_str("Friends").unwrap())); } @@ -245,7 +245,7 @@ mod tests { assert_eq!(roster.items[0].jid, Jid::from_str("nurse@example.com").unwrap()); assert!(roster.items[0].name.is_none()); assert!(roster.items[0].groups.is_empty()); - assert_eq!(roster.items[0].subscription, Some(Subscription::Remove)); + assert_eq!(roster.items[0].subscription, Subscription::Remove); } #[test]