scrappy_http/header/shared/
encoding.rs1use std::{fmt, str};
2
3pub use self::Encoding::{
4 Brotli, Chunked, Compress, Deflate, EncodingExt, Gzip, Identity, Trailers,
5};
6
7#[derive(Clone, PartialEq, Debug)]
10pub enum Encoding {
11 Chunked,
13 Brotli,
15 Gzip,
17 Deflate,
19 Compress,
21 Identity,
23 Trailers,
25 EncodingExt(String),
27}
28
29impl fmt::Display for Encoding {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 f.write_str(match *self {
32 Chunked => "chunked",
33 Brotli => "br",
34 Gzip => "gzip",
35 Deflate => "deflate",
36 Compress => "compress",
37 Identity => "identity",
38 Trailers => "trailers",
39 EncodingExt(ref s) => s.as_ref(),
40 })
41 }
42}
43
44impl str::FromStr for Encoding {
45 type Err = crate::error::ParseError;
46 fn from_str(s: &str) -> Result<Encoding, crate::error::ParseError> {
47 match s {
48 "chunked" => Ok(Chunked),
49 "br" => Ok(Brotli),
50 "deflate" => Ok(Deflate),
51 "gzip" => Ok(Gzip),
52 "compress" => Ok(Compress),
53 "identity" => Ok(Identity),
54 "trailers" => Ok(Trailers),
55 _ => Ok(EncodingExt(s.to_owned())),
56 }
57 }
58}