Struct mime_guess::MimeGuess [−][src]
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
impl MimeGuess
[src]
pub fn from_ext(ext: &str) -> MimeGuess
[src]
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.
pub fn from_path<P: AsRef<Path>>(path: P) -> MimeGuess
[src]
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.
pub fn is_empty(&self) -> bool
[src]
true
if the guess did not return any known mappings for the given path or extension.
pub fn count(&self) -> usize
[src]
Get the number of MIME types in the current guess.
pub fn first(&self) -> Option<Mime>
[src]
Get the first guessed Mime
, if applicable.
See Note: Ordering above.
pub fn first_raw(&self) -> Option<&'static str>
[src]
Get the first guessed Media Type as a string, if applicable.
See Note: Ordering above.
pub fn first_or_octet_stream(&self) -> Mime
[src]
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/content-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/content-stream
for non-text parts is safer. (RFC 7578, Section 4.4)
pub fn first_or_text_plain(&self) -> Mime
[src]
Get the first guessed Mime
, or if the guess is empty, return
text/plain
instead.
See Note: Ordering above.
pub fn first_or(&self, default: Mime) -> Mime
[src]
Get the first guessed Mime
, or if the guess is empty, return the given Mime
instead.
See Note: Ordering above.
pub fn first_or_else<F>(&self, default_fn: F) -> Mime where
F: FnOnce() -> Mime,
[src]
F: FnOnce() -> Mime,
Get the first guessed Mime
, or if the guess is empty, execute the closure and return its
result.
See Note: Ordering above.
pub fn iter(&self) -> Iterⓘ
[src]
Get an iterator over the Mime
values contained in this guess.
See Note: Ordering above.
pub fn iter_raw(&self) -> IterRawⓘ
[src]
Get an iterator over the raw media-type strings in this guess.
See Note: Ordering above.
Trait Implementations
impl Clone for MimeGuess
[src]
impl Copy for MimeGuess
[src]
impl Debug for MimeGuess
[src]
impl Eq for MimeGuess
[src]
impl IntoIterator for MimeGuess
[src]
type Item = Mime
The type of the elements being iterated over.
type IntoIter = Iter
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a> IntoIterator for &'a MimeGuess
[src]
type Item = Mime
The type of the elements being iterated over.
type IntoIter = Iter
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl PartialEq<MimeGuess> for MimeGuess
[src]
impl StructuralEq for MimeGuess
[src]
impl StructuralPartialEq for MimeGuess
[src]
Auto Trait Implementations
impl RefUnwindSafe for MimeGuess
impl Send for MimeGuess
impl Sync for MimeGuess
impl Unpin for MimeGuess
impl UnwindSafe for MimeGuess
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,