From a219501fed1c4aba544f1364eab866341802203e Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 25 Jun 2017 22:14:51 +0100 Subject: [PATCH] jingle, jingle_ft: Use the new generate_id! macro to simplify Sid/Cid generation. --- src/jingle.rs | 21 +++------------------ src/jingle_s5b.rs | 32 ++------------------------------ 2 files changed, 5 insertions(+), 48 deletions(-) diff --git a/src/jingle.rs b/src/jingle.rs index fad59aa..224bb54 100644 --- a/src/jingle.rs +++ b/src/jingle.rs @@ -245,29 +245,14 @@ impl IntoElements for ReasonElement { } } -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Sid(String); - -impl FromStr for Sid { - type Err = Error; - fn from_str(s: &str) -> Result { - // TODO: implement the NMTOKEN restrictions: https://www.w3.org/TR/2000/WD-xml-2e-20000814#NT-Nmtoken - Ok(Sid(String::from(s))) - } -} - -impl IntoAttributeValue for Sid { - fn into_attribute_value(self) -> Option { - return Some(self.0); - } -} +generate_id!(SessionId); #[derive(Debug, Clone)] pub struct Jingle { pub action: Action, pub initiator: Option, pub responder: Option, - pub sid: Sid, + pub sid: SessionId, pub contents: Vec, pub reason: Option, pub other: Vec, @@ -333,7 +318,7 @@ mod tests { let elem: Element = "".parse().unwrap(); let jingle = Jingle::try_from(elem).unwrap(); assert_eq!(jingle.action, Action::SessionInitiate); - assert_eq!(jingle.sid, Sid(String::from("coucou"))); + assert_eq!(jingle.sid, SessionId(String::from("coucou"))); } #[test] diff --git a/src/jingle_s5b.rs b/src/jingle_s5b.rs index b585cf1..cc916a3 100644 --- a/src/jingle_s5b.rs +++ b/src/jingle_s5b.rs @@ -25,37 +25,9 @@ generate_attribute!(Mode, "mode", { Udp => "udp", }, Default = Tcp); -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct CandidateId(String); +generate_id!(CandidateId); -impl FromStr for CandidateId { - type Err = Error; - fn from_str(s: &str) -> Result { - Ok(CandidateId(String::from(s))) - } -} - -impl IntoAttributeValue for CandidateId { - fn into_attribute_value(self) -> Option { - return Some(self.0); - } -} - -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct StreamId(String); - -impl FromStr for StreamId { - type Err = Error; - fn from_str(s: &str) -> Result { - Ok(StreamId(String::from(s))) - } -} - -impl IntoAttributeValue for StreamId { - fn into_attribute_value(self) -> Option { - return Some(self.0); - } -} +generate_id!(StreamId); #[derive(Debug, Clone)] pub struct Candidate {