quickfix_spec_parser/model/
message_category.rs1use std::str::FromStr;
2
3use quick_xml::events::BytesStart;
4
5use crate::{read_attribute, FixSpecError};
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum MessageCategory {
10 App,
12 Admin,
14}
15
16impl MessageCategory {
17 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}