jingle: Specialise Sid to get an increased type safety.

This commit is contained in:
Emmanuel Gil Peyrot 2017-06-14 02:28:42 +01:00
parent 216f6f8389
commit 48d340120c

View file

@ -245,12 +245,29 @@ 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<Sid, Error> {
// 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<String> {
return Some(self.0);
}
}
#[derive(Debug, Clone)]
pub struct Jingle {
pub action: Action,
pub initiator: Option<Jid>,
pub responder: Option<Jid>,
pub sid: String,
pub sid: Sid,
pub contents: Vec<Content>,
pub reason: Option<ReasonElement>,
pub other: Vec<Element>,