use std::str;
use actix_http::ContentEncoding;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Encoding {
Known(ContentEncoding),
Unknown(String),
}
impl_more::impl_display_enum! {
Encoding:
Known(enc) => ("{}", enc.as_str()),
Unknown(enc) => "{enc}",
}
impl Encoding {
pub const fn identity() -> Self {
Self::Known(ContentEncoding::Identity)
}
pub const fn brotli() -> Self {
Self::Known(ContentEncoding::Brotli)
}
pub const fn deflate() -> Self {
Self::Known(ContentEncoding::Deflate)
}
pub const fn gzip() -> Self {
Self::Known(ContentEncoding::Gzip)
}
pub const fn zstd() -> Self {
Self::Known(ContentEncoding::Zstd)
}
}
impl str::FromStr for Encoding {
type Err = crate::error::ParseError;
fn from_str(enc: &str) -> Result<Self, crate::error::ParseError> {
match enc.parse::<ContentEncoding>() {
Ok(enc) => Ok(Self::Known(enc)),
Err(_) => Ok(Self::Unknown(enc.to_owned())),
}
}
}