quickfix_spec_parser/
error.rs

1use std::{num::ParseIntError, string::FromUtf8Error};
2
3use thiserror::Error;
4
5/// Represent all possible error that can occurs when parsing XML spec file.
6#[derive(Debug, Error, PartialEq, Eq, Clone)]
7#[allow(missing_docs)]
8pub enum FixSpecError {
9    #[error("invalid document: {0}")]
10    InvalidDocument(&'static str),
11
12    #[error("invalid attribute: {0}")]
13    InvalidAttribute(String),
14
15    #[error("invalid content: {0}")]
16    InvalidContent(String),
17
18    #[error("xml error: {0}")]
19    Xml(String),
20}
21
22impl From<FromUtf8Error> for FixSpecError {
23    fn from(err: FromUtf8Error) -> Self {
24        Self::InvalidContent(err.to_string())
25    }
26}
27
28impl From<ParseIntError> for FixSpecError {
29    fn from(err: ParseIntError) -> Self {
30        Self::InvalidContent(err.to_string())
31    }
32}
33
34impl From<quick_xml::Error> for FixSpecError {
35    fn from(err: quick_xml::Error) -> Self {
36        Self::Xml(err.to_string())
37    }
38}