quickfix_spec_parser/model/
field_allowed_value.rs

1use std::io;
2
3use quick_xml::events::BytesStart;
4
5use crate::{read_attribute, FixSpecError, XmlObject, XmlReadable, XmlWritable, XmlWriter};
6
7/// XML `<field><value ...>` representation.
8#[derive(Debug, Clone)]
9pub struct FieldAllowedValue {
10    /// Associated value.
11    pub value: String,
12    /// Associated description / name.
13    pub description: String,
14}
15
16impl XmlObject for FieldAllowedValue {
17    const TAG_NAME: &'static str = "value";
18}
19
20impl XmlReadable for FieldAllowedValue {
21    fn parse_xml_node(element: &BytesStart) -> Result<Self, FixSpecError> {
22        let value = read_attribute(element, "enum")?;
23        let description = read_attribute(element, "description")?;
24        Ok(Self { value, description })
25    }
26}
27
28impl XmlWritable for FieldAllowedValue {
29    fn write_xml<'a>(&self, writer: &'a mut XmlWriter) -> io::Result<&'a mut XmlWriter> {
30        writer
31            .create_element(Self::TAG_NAME)
32            .with_attribute(("enum", self.value.as_str()))
33            .with_attribute(("description", self.description.as_str()))
34            .write_empty()
35    }
36}