use xml::attribute::{OwnedAttribute};
use std::string::{ToString};
#[derive(Debug)]
pub struct XmlAttribute<'a>
{
_attribute: &'a OwnedAttribute
}
impl<'a> XmlAttribute<'a>
{
pub fn new(attribute : &'a OwnedAttribute) -> XmlAttribute
{
XmlAttribute{_attribute:attribute}
}
pub fn name(&self) -> &'a str
{
&self._attribute.name.local_name
}
pub fn value(&self) -> &'a str
{
&self._attribute.value
}
}
impl<'a> ToString for XmlAttribute<'a>
{
fn to_string(&self) -> String
{
format!("{}=\"{}\"", self.name(), self.value())
}
}
#[cfg(test)]
mod xml_attribute_tests
{
use super::*;
use xml::name::{OwnedName};
#[test]
fn to_string_test()
{
let att = OwnedAttribute{name:owned_name_from("name"), value: "a value".to_owned()};
let attribute = XmlAttribute::new(&att);
assert_eq!(attribute.to_string(), "name=\"a value\"");
}
fn owned_name_from(name: &str) -> OwnedName
{
OwnedName{local_name: name.to_owned(), namespace: None, prefix: None}
}
}