Skip to main content

MediaTypeGuess

Struct MediaTypeGuess 

Source
pub struct MediaTypeGuess(/* private fields */);
Expand description

A guess of the media type(s) of a file extension or path, as one or more MediaType values.

§Ordering

A given file format may have one or more applicable media types. The first one is the one declared by the most recent IETF RFC or the one that explicitly supersedes all others; the ordering of the additional ones is arbitrary.

§Values are not stable

The exact media types returned by a guess are not part of the crate’s stable API and may be updated in patch releases to be as accurate as possible.

Implementations§

Source§

impl MediaTypeGuess

Source

pub fn from_ext(ext: &str) -> MediaTypeGuess

Guess the media type(s) of a file with the given extension.

The search is case-insensitive. If ext is empty or has no known media type, an empty guess is returned.

§Examples
assert_eq!(media_type::from_ext("png").first(), Some(media_type::IMAGE_PNG));
assert!(media_type::from_ext("").is_empty());
Source

pub fn from_path<P: AsRef<Path>>(path: P) -> MediaTypeGuess

Guess the media type(s) of path by its extension (as defined by Path::extension). No disk access is performed.

If path has no extension, its extension is not valid UTF-8, or it has no known media type, an empty guess is returned. The search is case-insensitive.

§Note

There is no guarantee that the contents of the file match the media type associated with its extension. Take care when making assumptions based on the return value of this function.

Source

pub fn is_empty(&self) -> bool

Returns true if the guess did not find any media type for the given extension or path.

Source

pub fn count(&self) -> usize

Return the number of media types in this guess.

Source

pub fn first(&self) -> Option<MediaType>

Get the first guessed MediaType, if any.

Source

pub fn first_raw(&self) -> Option<&'static str>

Get the first guessed media type as a raw string, if any.

Source

pub fn first_or_octet_stream(&self) -> MediaType

Get the first guessed MediaType, or APPLICATION_OCTET_STREAM if the guess is empty.

Source

pub fn first_or_text_plain(&self) -> MediaType

Get the first guessed MediaType, or TEXT_PLAIN if the guess is empty.

Source

pub fn first_or(&self, default: MediaType) -> MediaType

Get the first guessed MediaType, or the given default if the guess is empty.

Source

pub fn first_or_else<F>(&self, default: F) -> MediaType
where F: FnOnce() -> MediaType,

Get the first guessed MediaType, or the result of default if the guess is empty.

Source

pub fn iter(&self) -> Iter ⓘ

Return an iterator over the MediaType values contained in this guess.

Source

pub fn iter_raw(&self) -> IterRaw ⓘ

Return an iterator over the raw media type strings contained in this guess.

Trait Implementations§

Source§

impl Clone for MediaTypeGuess

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for MediaTypeGuess

Source§

impl Debug for MediaTypeGuess

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for MediaTypeGuess

Source§

impl IntoIterator for MediaTypeGuess

Available on crate feature alloc only.
Source§

type Item = MediaType

The type of the elements being iterated over.
Source§

type IntoIter = Iter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a MediaTypeGuess

Available on crate feature alloc only.
Source§

type Item = MediaType

The type of the elements being iterated over.
Source§

type IntoIter = Iter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for MediaTypeGuess

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MediaTypeGuess

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.