pub struct MediaType {
pub typ: String,
pub subtype: String,
pub params: Vec<(String, String)>,
}Expand description
A parsed media type (MIME type) with optional parameters.
Represents types like text/html, application/json, or
text/html; charset=utf-8.
Fields§
§typ: StringThe primary type (e.g., “text”, “application”, “image”).
subtype: StringThe subtype (e.g., “html”, “json”, “png”).
params: Vec<(String, String)>Optional parameters (e.g., charset, boundary).
Implementations§
Source§impl MediaType
impl MediaType
Sourcepub fn new(typ: impl Into<String>, subtype: impl Into<String>) -> Self
pub fn new(typ: impl Into<String>, subtype: impl Into<String>) -> Self
Create a new media type without parameters.
Sourcepub fn matches(&self, other: &MediaType) -> bool
pub fn matches(&self, other: &MediaType) -> bool
Check if this media type matches another, supporting wildcards.
A wildcard * matches any value.
§Example
ⓘ
let html = MediaType::new("text", "html");
let any_text = MediaType::new("text", "*");
let any = MediaType::new("*", "*");
assert!(html.matches(&any_text));
assert!(html.matches(&any));
assert!(!any_text.matches(&html)); // wildcard doesn't match specificTrait Implementations§
impl StructuralPartialEq for MediaType
Auto Trait Implementations§
impl Freeze for MediaType
impl RefUnwindSafe for MediaType
impl Send for MediaType
impl Sync for MediaType
impl Unpin for MediaType
impl UnwindSafe for MediaType
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).