einfach_xml_builder/
namespace.rs

1use crate::Attribute;
2
3/// Represents a namespace in XML.
4pub struct Namespace<'a>(Attribute<'a>);
5
6impl<'a> Namespace<'a> {
7    /// Creates a new instance of `Namespace` with the given prefix and URI.
8    ///
9    /// # Arguments
10    ///
11    /// * `prefix` - The prefix for the namespace.
12    /// * `uri` - The URI associated with the namespace.
13    ///
14    /// # Example
15    ///
16    /// ```
17    /// let namespace = Namespace::new("xmlns", "http://example.com");
18    /// ```
19    pub fn new(prefix: &'a str, uri: &'a str) -> Self {
20        Namespace(Attribute::new(prefix, uri))
21    }
22}
23
24impl std::fmt::Display for Namespace<'_> {
25    /// Formats the namespace as a string in the format `xmlns:prefix="uri"`.
26    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27        write!(f, "xmlns:{}", self.0.to_string())?;
28        Ok(())
29    }
30}