quickfix_spec_parser/model/
message_category.rs

1use std::str::FromStr;
2
3use quick_xml::events::BytesStart;
4
5use crate::{read_attribute, FixSpecError};
6
7/// Message dest.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum MessageCategory {
10    /// Message is targeting application level.
11    App,
12    /// Message is related to protocol / admin / technical task.
13    Admin,
14}
15
16impl MessageCategory {
17    /// Convert value to a static string.
18    ///
19    /// Mostly useful for debugging / display purpose.
20    pub const fn as_static_str(&self) -> &'static str {
21        match self {
22            MessageCategory::App => "app",
23            MessageCategory::Admin => "admin",
24        }
25    }
26
27    pub(crate) fn parse_xml_element(element: &BytesStart) -> Result<Self, FixSpecError> {
28        let item = read_attribute(element, "msgcat")?.parse()?;
29        Ok(item)
30    }
31}
32
33impl FromStr for MessageCategory {
34    type Err = FixSpecError;
35
36    fn from_str(input: &str) -> Result<Self, Self::Err> {
37        match input {
38            "admin" => Ok(Self::Admin),
39            "app" => Ok(Self::App),
40            x => Err(FixSpecError::InvalidContent(format!("invalid msgcat: {x}"))),
41        }
42    }
43}