Struct http_types::content::ContentType
source · 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 new<U>(media_type: U) -> Selfwhere
U: TryInto<Mime>,
U::Error: Debug,
pub fn new<U>(media_type: U) -> Selfwhere U: TryInto<Mime>, U::Error: Debug,
Create a new instance.
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
Auto Trait Implementations§
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