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
impl MediaTypeGuess
Sourcepub fn from_ext(ext: &str) -> MediaTypeGuess
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());Sourcepub fn from_path<P: AsRef<Path>>(path: P) -> MediaTypeGuess
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.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the guess did not find any media type for the given extension or path.
Sourcepub fn first_raw(&self) -> Option<&'static str>
pub fn first_raw(&self) -> Option<&'static str>
Get the first guessed media type as a raw string, if any.
Sourcepub fn first_or_octet_stream(&self) -> MediaType
pub fn first_or_octet_stream(&self) -> MediaType
Get the first guessed MediaType, or APPLICATION_OCTET_STREAM if the guess is empty.
Sourcepub fn first_or_text_plain(&self) -> MediaType
pub fn first_or_text_plain(&self) -> MediaType
Get the first guessed MediaType, or TEXT_PLAIN if the guess is empty.
Sourcepub fn first_or(&self, default: MediaType) -> MediaType
pub fn first_or(&self, default: MediaType) -> MediaType
Get the first guessed MediaType, or the given default if the guess is empty.
Sourcepub fn first_or_else<F>(&self, default: F) -> MediaType
pub fn first_or_else<F>(&self, default: F) -> MediaType
Get the first guessed MediaType, or the result of default if the guess is empty.
Trait Implementations§
Source§impl Clone for MediaTypeGuess
impl Clone for MediaTypeGuess
impl Copy for MediaTypeGuess
Source§impl Debug for MediaTypeGuess
impl Debug for MediaTypeGuess
impl Eq for MediaTypeGuess
Source§impl IntoIterator for MediaTypeGuess
Available on crate feature alloc only.
impl IntoIterator for MediaTypeGuess
alloc only.Source§impl<'a> IntoIterator for &'a MediaTypeGuess
Available on crate feature alloc only.
impl<'a> IntoIterator for &'a MediaTypeGuess
alloc only.