pub struct MimeGuess(/* private fields */);
Expand description
A “guess” of the MIME/Media Type(s) of an extension or path as one or more
Mime
instances.
§Note: Ordering
A given file format may have one or more applicable Media Types; in this case the first Media Type returned is whatever is declared in the latest IETF RFC for the presumed file format or the one that explicitly supercedes all others. Ordering of additional Media Types is arbitrary.
§Note: Values Not Stable
The exact Media Types returned in any given guess are not considered to be stable and are often updated in patch releases in order to reflect the most up-to-date information possible.
Implementations§
source§impl MimeGuess
impl MimeGuess
sourcepub fn from_ext(ext: &str) -> MimeGuess
pub fn from_ext(ext: &str) -> MimeGuess
Guess the MIME type of a file (real or otherwise) with the given extension.
The search is case-insensitive.
If ext
is empty or has no (currently) known MIME type mapping, then an empty guess is
returned.
sourcepub fn from_path<P: AsRef<Path>>(path: P) -> MimeGuess
pub fn from_path<P: AsRef<Path>>(path: P) -> MimeGuess
Guess the MIME type of path
by its extension (as defined by
Path::extension()
). No disk access is performed.
If path
has no extension, the extension cannot be converted to str
, or has
no known MIME type mapping, then an empty guess is returned.
The search is case-insensitive.
§Note
Guess is the operative word here, as there are no guarantees that the contents of the
file that path
points to match the MIME type associated with the path’s extension.
Take care when processing files with assumptions based on the return value of this function.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
true
if the guess did not return any known mappings for the given path or extension.
sourcepub fn first(&self) -> Option<Mime>
pub fn first(&self) -> Option<Mime>
Get the first guessed Mime
, if applicable.
See Note: Ordering above.
sourcepub fn first_raw(&self) -> Option<&'static str>
pub fn first_raw(&self) -> Option<&'static str>
Get the first guessed Media Type as a string, if applicable.
See Note: Ordering above.
sourcepub fn first_or_octet_stream(&self) -> Mime
pub fn first_or_octet_stream(&self) -> Mime
Get the first guessed Mime
, or if the guess is empty, return
application/octet-stream
instead.
See Note: Ordering above.
§Note: HTTP Applications
For HTTP request and response bodies if a value for the Content-Type
header
cannot be determined it might be preferable to not send one at all instead of defaulting to
application/octet-stream
as the recipient will expect to infer the format directly from
the content instead. (RFC 7231, Section 3.1.1.5)
On the contrary, for multipart/form-data
bodies, the Content-Type
of a form-data part is
assumed to be text/plain
unless specified so a default of application/octet-stream
for non-text parts is safer. (RFC 7578, Section 4.4)
sourcepub fn first_or_text_plain(&self) -> Mime
pub fn first_or_text_plain(&self) -> Mime
Get the first guessed Mime
, or if the guess is empty, return
text/plain
instead.
See Note: Ordering above.
sourcepub fn first_or(&self, default: Mime) -> Mime
pub fn first_or(&self, default: Mime) -> Mime
Get the first guessed Mime
, or if the guess is empty, return the given Mime
instead.
See Note: Ordering above.
sourcepub fn first_or_else<F>(&self, default_fn: F) -> Mime
pub fn first_or_else<F>(&self, default_fn: F) -> Mime
Get the first guessed Mime
, or if the guess is empty, execute the closure and return its
result.
See Note: Ordering above.
sourcepub fn iter(&self) -> Iter ⓘ
pub fn iter(&self) -> Iter ⓘ
Get an iterator over the Mime
values contained in this guess.
See Note: Ordering above.
sourcepub fn iter_raw(&self) -> IterRaw ⓘ
pub fn iter_raw(&self) -> IterRaw ⓘ
Get an iterator over the raw media-type strings in this guess.
See Note: Ordering above.
Trait Implementations§
source§impl<'a> IntoIterator for &'a MimeGuess
impl<'a> IntoIterator for &'a MimeGuess
source§impl IntoIterator for MimeGuess
impl IntoIterator for MimeGuess
impl Copy for MimeGuess
impl Eq for MimeGuess
impl StructuralPartialEq for MimeGuess
Auto Trait Implementations§
impl Freeze for MimeGuess
impl RefUnwindSafe for MimeGuess
impl Send for MimeGuess
impl Sync for MimeGuess
impl Unpin for MimeGuess
impl UnwindSafe for MimeGuess
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)