Struct ajars_surf::surf::http::content::ContentType
[−]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
impl ContentType
impl ContentType
pub fn new<U>(media_type: U) -> ContentType where
U: TryInto<Mime>,
<U as TryInto<Mime>>::Error: Debug,
pub fn new<U>(media_type: U) -> ContentType where
U: TryInto<Mime>,
<U as TryInto<Mime>>::Error: Debug,
Create a new instance.
pub fn from_headers(
headers: impl AsRef<Headers>
) -> Result<Option<ContentType>, Error>
pub fn from_headers(
headers: impl AsRef<Headers>
) -> Result<Option<ContentType>, Error>
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.
pub fn name(&self) -> HeaderName
pub fn name(&self) -> HeaderName
Get the HeaderName
.
pub fn value(&self) -> HeaderValue
pub fn value(&self) -> HeaderValue
Get the HeaderValue
.
Trait Implementations
impl Debug for ContentType
impl Debug for ContentType
impl From<Mime> for ContentType
impl From<Mime> for ContentType
fn from(media_type: Mime) -> ContentType
fn from(media_type: Mime) -> ContentType
Converts to this type from the input type.
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more