mco_http/header/shared/
encoding.rs1use std::fmt;
2use std::str;
3
4pub use self::Encoding::{Chunked, Gzip, Deflate, Compress, Identity, EncodingExt};
5
6#[derive(Clone, PartialEq, Debug)]
9pub enum Encoding {
10 Chunked,
12 Gzip,
14 Deflate,
16 Compress,
18 Identity,
20 EncodingExt(String)
22}
23
24impl fmt::Display for Encoding {
25 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
26 f.write_str(match *self {
27 Chunked => "chunked",
28 Gzip => "gzip",
29 Deflate => "deflate",
30 Compress => "compress",
31 Identity => "identity",
32 EncodingExt(ref s) => s.as_ref()
33 })
34 }
35}
36
37impl str::FromStr for Encoding {
38 type Err = crate::Error;
39 fn from_str(s: &str) -> crate::Result<Encoding> {
40 match s {
41 "chunked" => Ok(Chunked),
42 "deflate" => Ok(Deflate),
43 "gzip" => Ok(Gzip),
44 "compress" => Ok(Compress),
45 "identity" => Ok(Identity),
46 _ => Ok(EncodingExt(s.to_owned()))
47 }
48 }
49}