1use xml::attribute::{OwnedAttribute};
2
3use std::string::{ToString};
4
5#[derive(Debug)]
6pub struct XmlAttribute<'a>
7{
8 _attribute: &'a OwnedAttribute
9}
10
11impl<'a> XmlAttribute<'a>
12{
13 pub fn new(attribute : &'a OwnedAttribute) -> XmlAttribute
14 {
15 XmlAttribute{_attribute:attribute}
16 }
17
18 pub fn name(&self) -> &'a str
19 {
20 &self._attribute.name.local_name
21 }
22
23 pub fn value(&self) -> &'a str
24 {
25 &self._attribute.value
26 }
27}
28
29impl<'a> ToString for XmlAttribute<'a>
30{
31 fn to_string(&self) -> String
32 {
33
34 format!("{}=\"{}\"", self.name(), self.value())
35 }
36}
37
38#[cfg(test)]
39mod xml_attribute_tests
40{
41 use super::*;
42
43 use xml::name::{OwnedName};
44
45 #[test]
46 fn to_string_test()
47 {
48 let att = OwnedAttribute{name:owned_name_from("name"), value: "a value".to_owned()};
49 let attribute = XmlAttribute::new(&att);
50 assert_eq!(attribute.to_string(), "name=\"a value\"");
51 }
52
53 fn owned_name_from(name: &str) -> OwnedName
54 {
55 OwnedName{local_name: name.to_owned(), namespace: None, prefix: None}
56 }
57}