1use core::fmt;
2
3use std::error;
4
5#[derive(Debug)]
7#[non_exhaustive]
8pub enum EncodingError {
9 MissingFeature(FeatureError),
10 ParseAcceptEncoding,
11}
12
13impl fmt::Display for EncodingError {
14 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15 match *self {
16 Self::MissingFeature(ref e) => write!(f, "{e}"),
17 Self::ParseAcceptEncoding => write!(f, "failed to parse Accept-Encoding header value"),
18 }
19 }
20}
21
22impl error::Error for EncodingError {}
23
24#[derive(Debug)]
26#[non_exhaustive]
27pub enum FeatureError {
28 Br,
29 Gzip,
30 Deflate,
31 Unknown(Box<str>),
32}
33
34impl fmt::Display for FeatureError {
35 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36 match *self {
37 Self::Br => feature_error_fmt("brotil", f),
38 Self::Gzip => feature_error_fmt("gzip", f),
39 Self::Deflate => feature_error_fmt("deflate", f),
40 Self::Unknown(ref encoding) => feature_error_fmt(encoding, f),
41 }
42 }
43}
44
45#[cold]
46#[inline(never)]
47fn feature_error_fmt(encoding: impl fmt::Display, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 write!(f, "Content-Encoding: {encoding} is not supported.")
49}
50
51impl error::Error for FeatureError {}
52
53impl From<FeatureError> for EncodingError {
54 fn from(e: FeatureError) -> Self {
55 Self::MissingFeature(e)
56 }
57}
58
59pub type CoderError = Box<dyn error::Error + Send + Sync>;