use std::sync::Arc;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ContentType(Arc<str>);
impl ContentType {
#[must_use]
pub fn new(name: impl Into<Arc<str>>) -> Self {
Self(name.into())
}
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
#[must_use]
pub fn is_text(&self) -> bool {
self.0.starts_with("text/")
}
#[must_use]
pub fn is_binary(&self) -> bool {
self.0.starts_with("binary/")
}
}
impl std::fmt::Display for ContentType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl ContentType {
pub const UTF8: &'static str = "text/utf-8";
pub const BINARY_RAW: &'static str = "binary/raw";
}
#[cfg(test)]
#[path = "content_type_tests.rs"]
mod tests;