hyper_sync/header/shared/
encoding.rs

1use std::fmt;
2use std::str;
3
4pub use self::Encoding::{Chunked, Brotli, Gzip, Deflate, Compress, Identity, EncodingExt, Trailers};
5
6/// A value to represent an encoding used in `Transfer-Encoding`
7/// or `Accept-Encoding` header.
8#[derive(Clone, PartialEq, Debug)]
9pub enum Encoding {
10    /// The `chunked` encoding.
11    Chunked,
12    /// The `br` encoding.
13    Brotli,
14    /// The `gzip` encoding.
15    Gzip,
16    /// The `deflate` encoding.
17    Deflate,
18    /// The `compress` encoding.
19    Compress,
20    /// The `identity` encoding.
21    Identity,
22    /// The `trailers` encoding.
23    Trailers,
24    /// Some other encoding that is less common, can be any String.
25    EncodingExt(String)
26}
27
28impl fmt::Display for Encoding {
29    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
30        f.write_str(match *self {
31            Chunked => "chunked",
32            Brotli => "br",
33            Gzip => "gzip",
34            Deflate => "deflate",
35            Compress => "compress",
36            Identity => "identity",
37            Trailers => "trailers",
38            EncodingExt(ref s) => s.as_ref()
39        })
40    }
41}
42
43impl str::FromStr for Encoding {
44    type Err = ::Error;
45    fn from_str(s: &str) -> ::Result<Encoding> {
46        match s {
47            "chunked" => Ok(Chunked),
48            "br" => Ok(Brotli),
49            "deflate" => Ok(Deflate),
50            "gzip" => Ok(Gzip),
51            "compress" => Ok(Compress),
52            "identity" => Ok(Identity),
53            "trailers" => Ok(Trailers),
54            _ => Ok(EncodingExt(s.to_owned()))
55        }
56    }
57}