pub struct MediaType<'a> { /* private fields */ }Expand description
A validated media type.
§Examples
let ld = parse_net::parse_media_type(b"application/ld+json")?;
assert_eq!(ld.suffix(), Some(&b"json"[..]));
assert!(ld.is_json());Implementations§
Source§impl<'a> MediaType<'a>
impl<'a> MediaType<'a>
Sourcepub fn suffix(&self) -> Option<&'a [u8]>
pub fn suffix(&self) -> Option<&'a [u8]>
The structured syntax suffix: the part of the subtype after its last
+ (json of ld+json), when there is one.
Sourcepub fn essence_is(&self, essence: &str) -> bool
pub fn essence_is(&self, essence: &str) -> bool
Whether type/subtype equals essence, ignoring ASCII case.
Sourcepub fn is(&self, type_: &str, subtype: &str) -> bool
pub fn is(&self, type_: &str, subtype: &str) -> bool
Whether the type and subtype equal type_ and subtype, ignoring
ASCII case.
Sourcepub fn param(&self, name: &str) -> Option<Word<'a>>
pub fn param(&self, name: &str) -> Option<Word<'a>>
The value of the parameter name (ASCII case-insensitive).
Sourcepub fn charset(&self) -> Option<Word<'a>>
pub fn charset(&self) -> Option<Word<'a>>
The charset parameter. Compare it case-insensitively.
Sourcepub fn boundary(&self) -> Result<Option<Boundary<'a>>, ParseError>
pub fn boundary(&self) -> Result<Option<Boundary<'a>>, ParseError>
The boundary parameter, validated by RFC 2046 section 5.1.1: 1 to 70
bchars, the last not a space. Ok(None) when absent.
§Errors
ErrorKind::InvalidBoundary, with the offset inside the boundary
value.
Sourcepub fn is_form_urlencoded(&self) -> bool
pub fn is_form_urlencoded(&self) -> bool
Whether this is application/x-www-form-urlencoded.
Sourcepub fn is_multipart_form_data(&self) -> bool
pub fn is_multipart_form_data(&self) -> bool
Whether this is multipart/form-data.
Sourcepub fn write_canonical(&self, out: &mut impl Sink) -> Result<(), WriteError>
pub fn write_canonical(&self, out: &mut impl Sink) -> Result<(), WriteError>
Writes the media type with the type, subtype, and parameter names in
lowercase and the values as sent, separated by ; .
§Errors
WriteError::Full; nothing is written when the sink reports its
room.
§Examples
use parse_net::{parse_media_type, SliceSink};
let mt = parse_media_type(b"Text/HTML;Charset=\"UTF-8\"")?;
let mut buf = [0u8; 64];
let mut out = SliceSink::new(&mut buf);
mt.write_canonical(&mut out).expect("room");
assert_eq!(out.written(), b"text/html; charset=\"UTF-8\"");