pub struct ContentType { /* private fields */ }
Expand description
Indicate the media type of a resource’s content.
§Specifications
§Examples
use http_types::content::ContentType;
use http_types::{Response, Mime};
use std::str::FromStr;
let content_type = ContentType::new("text/*");
let mut res = Response::new(200);
content_type.apply(&mut res);
let content_type = ContentType::from_headers(res)?.unwrap();
assert_eq!(content_type.value(), format!("{}", Mime::from_str("text/*")?).as_str());
Implementations§
Source§impl ContentType
impl ContentType
Sourcepub fn from_headers(headers: impl AsRef<Headers>) -> Result<Option<Self>>
pub fn from_headers(headers: impl AsRef<Headers>) -> Result<Option<Self>>
Create a new instance from headers.
Content-Type
headers can provide both full and partial URLs. In
order to always return fully qualified URLs, a base URL must be passed to
reference the current environment. In HTTP/1.1 and above this value can
always be determined from the request.
Sourcepub fn name(&self) -> HeaderName
pub fn name(&self) -> HeaderName
Get the HeaderName
.
Sourcepub fn value(&self) -> HeaderValue
pub fn value(&self) -> HeaderValue
Get the HeaderValue
.
Trait Implementations§
Source§impl Debug for ContentType
impl Debug for ContentType
Source§impl From<Mime> for ContentType
impl From<Mime> for ContentType
Source§impl PartialEq<&Mime> for ContentType
impl PartialEq<&Mime> for ContentType
Source§impl PartialEq<Mime> for ContentType
impl PartialEq<Mime> for ContentType
Auto Trait Implementations§
impl Freeze for ContentType
impl RefUnwindSafe for ContentType
impl Send for ContentType
impl Sync for ContentType
impl Unpin for ContentType
impl UnwindSafe for ContentType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more