Convert all of the parsers/serialisers into consuming their parameter.

This commit is contained in:
Emmanuel Gil Peyrot 2017-05-23 23:31:33 +01:00
commit 16e43c0b01
26 changed files with 378 additions and 382 deletions

View file

@ -15,10 +15,10 @@ use ns;
#[derive(Debug, Clone)]
pub struct Attention;
impl<'a> TryFrom<&'a Element> for Attention {
impl TryFrom<Element> for Attention {
type Error = Error;
fn try_from(elem: &'a Element) -> Result<Attention, Error> {
fn try_from(elem: Element) -> Result<Attention, Error> {
if !elem.is("attention", ns::ATTENTION) {
return Err(Error::ParseError("This is not an attention element."));
}
@ -29,7 +29,7 @@ impl<'a> TryFrom<&'a Element> for Attention {
}
}
impl<'a> Into<Element> for &'a Attention {
impl Into<Element> for Attention {
fn into(self) -> Element {
Element::builder("attention")
.ns(ns::ATTENTION)
@ -47,13 +47,13 @@ mod tests {
#[test]
fn test_simple() {
let elem: Element = "<attention xmlns='urn:xmpp:attention:0'/>".parse().unwrap();
Attention::try_from(&elem).unwrap();
Attention::try_from(elem).unwrap();
}
#[test]
fn test_invalid_child() {
let elem: Element = "<attention xmlns='urn:xmpp:attention:0'><coucou/></attention>".parse().unwrap();
let error = Attention::try_from(&elem).unwrap_err();
let error = Attention::try_from(elem).unwrap_err();
let message = match error {
Error::ParseError(string) => string,
_ => panic!(),
@ -65,9 +65,7 @@ mod tests {
fn test_serialise() {
let elem: Element = "<attention xmlns='urn:xmpp:attention:0'/>".parse().unwrap();
let attention = Attention;
let elem2: Element = (&attention).into();
let elem3: Element = (&attention).into();
let elem2: Element = attention.into();
assert_eq!(elem, elem2);
assert_eq!(elem2, elem3);
}
}