einfach_xml_builder/
attribute.rs

1/// Represents an XML attribute with a name and value.
2pub struct Attribute<'a> {
3    /// The name of the attribute.
4    name: &'a str,
5    /// The value of the attribute.
6    value: &'a str,
7}
8
9impl<'a> Attribute<'a> {
10    /// Creates a new instance of `Attribute`.
11    ///
12    /// # Arguments
13    ///
14    /// * `name` - The name of the attribute.
15    /// * `value` - The value of the attribute.
16    ///
17    /// # Example
18    ///
19    /// ```
20    /// let attribute = Attribute::new("name", "value");
21    /// ```
22    pub fn new(name: &'a str, value: &'a str) -> Self {
23        Attribute {
24            name,
25            value,
26        }
27    }
28}
29
30impl std::fmt::Display for Attribute<'_> {
31    /// Formats the attribute as a string in the format `name="value"`.
32    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33        write!(f, "{}=\"{}\"", self.name, self.value)?;
34        Ok(())
35    }
36}