put Attribute into its own module, take into account prefixes when determining namespaces

This commit is contained in:
lumi 2017-02-19 23:29:19 +01:00
commit 2d97e2d5d9
2 changed files with 40 additions and 23 deletions

24
src/attribute.rs Normal file
View file

@ -0,0 +1,24 @@
use xml::escape::escape_str_attribute;
use std::fmt;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Attribute {
pub name: String,
pub value: String,
}
impl fmt::Display for Attribute {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{}=\"{}\"", self.name, escape_str_attribute(&self.value))
}
}
impl Attribute {
pub fn new<N: Into<String>, V: Into<String>>(name: N, value: V) -> Attribute {
Attribute {
name: name.into(),
value: value.into(),
}
}
}