mediatype/
error.rs

1use std::{error, fmt};
2
3/// Media-type format error.
4#[non_exhaustive]
5#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
6pub enum MediaTypeError {
7    /// The top-level type name is not valid.
8    InvalidTypeName,
9    /// The subtype name is not valid.
10    InvalidSubtypeName,
11    /// The suffix name is not valid.
12    InvalidSuffix,
13    /// The parameter syntax is not valid.
14    InvalidParams,
15    /// An invalid parameter name is detected.
16    InvalidParamName,
17    /// An invalid parameter value is detected.
18    InvalidParamValue,
19}
20
21impl fmt::Display for MediaTypeError {
22    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23        let msg = match self {
24            Self::InvalidTypeName => "Invalid type name",
25            Self::InvalidSubtypeName => "Invalid subtype name",
26            Self::InvalidSuffix => "Invalid suffix",
27            Self::InvalidParams => "Invalid params",
28            Self::InvalidParamName => "Invalid param name",
29            Self::InvalidParamValue => "Invalid param value",
30        };
31        f.write_str(msg)
32    }
33}
34
35impl error::Error for MediaTypeError {}