From 54f404025125e18e8c008feae0a8648d108d6c23 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 23 Apr 2017 03:20:52 +0100 Subject: [PATCH] attention: Simplify the payload type, and add a serialise function. --- src/attention.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/attention.rs b/src/attention.rs index 2438dc6..f64dbf5 100644 --- a/src/attention.rs +++ b/src/attention.rs @@ -5,9 +5,7 @@ use error::Error; use ns; #[derive(Debug, Clone)] -pub enum Attention { - Attention, -} +pub struct Attention; pub fn parse_attention(root: &Element) -> Result { if !root.is("attention", ns::ATTENTION) { @@ -16,7 +14,13 @@ pub fn parse_attention(root: &Element) -> Result { for _ in root.children() { return Err(Error::ParseError("Unknown child in attention element.")); } - Ok(Attention::Attention) + Ok(Attention) +} + +pub fn serialise(_: &Attention) -> Element { + Element::builder("attention") + .ns(ns::ATTENTION) + .build() } #[cfg(test)] @@ -41,4 +45,12 @@ mod tests { }; assert_eq!(message, "Unknown child in attention element."); } + + #[test] + fn test_serialise() { + let elem: Element = "".parse().unwrap(); + let attention = attention::Attention; + let elem2 = attention::serialise(&attention); + assert_eq!(elem, elem2); + } }