[][src]Struct mime_guess::MimeGuess

pub struct MimeGuess(_);

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.

Methods

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]

Get the first guessed Mime, or if the guess is empty, execute the closure and return its result.

See Note: Ordering above.

Important traits for Iter
pub fn iter(&self) -> Iter[src]

Get an iterator over the Mime values contained in this guess.

See Note: Ordering above.

Important traits for IterRaw
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]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

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?

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?

impl PartialEq<MimeGuess> for MimeGuess[src]

impl Copy for MimeGuess[src]

impl Eq for MimeGuess[src]

impl Debug for MimeGuess[src]

Auto Trait Implementations

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]