Struct xdg_mime::SharedMimeInfo

source ·
pub struct SharedMimeInfo { /* private fields */ }
Expand description

The shared MIME info database.

Implementations§

source§

impl SharedMimeInfo

source

pub fn new() -> SharedMimeInfo

Creates a new SharedMimeInfo instance containing all MIME information under the standard XDG base directories.

source

pub fn new_for_directory<P: AsRef<Path>>(directory: P) -> SharedMimeInfo

Loads all the MIME information under directory, and creates a new SharedMimeInfo instance for it.

This method is only really useful for testing purposes; you should always use the new method, instead.

source

pub fn reload(&mut self) -> bool

Reloads the contents of the SharedMimeInfo type from the directories used to populate it at construction time. You should use this method if you’re planning to keep the database around for long running operations or applications.

This method does not do anything if the directories haven’t changed since the time they were loaded last.

This method will return true if the contents of the shared MIME database were updated.

source

pub fn unalias_mime_type(&self, mime_type: &Mime) -> Option<Mime>

Retrieves the MIME type aliased by a MIME type, if any.

source

pub fn lookup_icon_names(&self, mime_type: &Mime) -> Vec<String>

Looks up the icons associated to a MIME type.

The icons can be looked up within the current icon theme.

source

pub fn lookup_generic_icon_name(&self, mime_type: &Mime) -> Option<String>

Looks up the generic icon associated to a MIME type.

The icon can be looked up within the current icon theme.

source

pub fn get_parents(&self, mime_type: &Mime) -> Option<Vec<Mime>>

Retrieves all the parent MIME types associated to mime_type.

source

pub fn get_mime_types_from_file_name(&self, file_name: &str) -> Vec<Mime>

Retrieves the list of matching MIME types for the given file name, without looking at the data inside the file.

If no specific MIME-type can be determined, returns a single element vector containing the application/octet-stream MIME type.

// let mime_db = ...
let mime_types: Vec<Mime> = mime_db.get_mime_types_from_file_name("file.txt");
assert_eq!(mime_types, vec![Mime::from_str("text/plain")?]);
source

pub fn get_mime_type_for_data(&self, data: &[u8]) -> Option<(Mime, u32)>

Retrieves the MIME type for the given data, and the priority of the match. A priority above 80 means a certain match.

source

pub fn mime_type_equal(&self, mime_a: &Mime, mime_b: &Mime) -> bool

Checks whether two MIME types are equal, taking into account eventual aliases.

// let mime_db = ...
let x_markdown: Mime = "text/x-markdown".parse()?;
let markdown: Mime = "text/markdown".parse()?;
assert!(mime_db.mime_type_equal(&x_markdown, &markdown));
source

pub fn mime_type_subclass(&self, mime_type: &Mime, base: &Mime) -> bool

Checks whether a MIME type is a subclass of another MIME type.

// let mime_db = ...
let rust: Mime = "text/rust".parse()?;
let text: Mime = "text/plain".parse()?;
assert!(mime_db.mime_type_subclass(&rust, &text));
source

pub fn guess_mime_type(&self) -> GuessBuilder<'_>

Creates a new GuessBuilder that can be used to guess the MIME type of a file name, its contents, or a path.

// let mime_db = ...
let mut gb = mime_db.guess_mime_type();
let guess = gb.file_name("foo.txt").guess();
assert_eq!(guess.mime_type(), &mime::TEXT_PLAIN);
assert_eq!(guess.uncertain(), false);

Trait Implementations§

source§

impl Default for SharedMimeInfo

source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.