Skip to main content

refix_dictionary/transport/
error.rs

1use crate::Tag;
2use std::fmt;
3
4/// Why an application dictionary and a transport dictionary cannot be
5/// one dictionary.
6#[derive(Clone, Debug, Eq, PartialEq)]
7pub enum Error {
8    /// The application dictionary has members in its own header.
9    ApplicationHeader,
10    /// The application dictionary has members in its own trailer.
11    ApplicationTrailer,
12    /// The transport dictionary has no header to give.
13    NoTransportHeader,
14    /// A name or tag that means one field in the application dictionary
15    /// and another in the transport.
16    FieldMismatch {
17        application: (String, Tag),
18        transport: (String, Tag),
19    },
20}
21
22impl fmt::Display for Error {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        match self {
25            Error::ApplicationHeader => {
26                write!(f, "the application dictionary has a header of its own")
27            }
28            Error::ApplicationTrailer => {
29                write!(f, "the application dictionary has a trailer of its own")
30            }
31            Error::NoTransportHeader => write!(f, "the transport dictionary has no header"),
32            Error::FieldMismatch {
33                application,
34                transport,
35            } => write!(
36                f,
37                "field '{}' ({}) in the application dictionary is '{}' ({}) in the transport",
38                application.0, application.1, transport.0, transport.1
39            ),
40        }
41    }
42}
43
44impl std::error::Error for Error {}