pub struct MimeGuess(_);
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

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.

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.

true if the guess did not return any known mappings for the given path or extension.

Get the number of MIME types in the current guess.

Get the first guessed Mime, if applicable.

See Note: Ordering above.

Get the first guessed Media Type as a string, if applicable.

See Note: Ordering above.

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)

Get the first guessed Mime, or if the guess is empty, return text/plain instead.

See Note: Ordering above.

Get the first guessed Mime, or if the guess is empty, return the given Mime instead.

See Note: Ordering above.

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

See Note: Ordering above.

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

See Note: Ordering above.

Get an iterator over the raw media-type strings in this guess.

See Note: Ordering above.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.