Struct xdg_mime::SharedMimeInfo
source · pub struct SharedMimeInfo { /* private fields */ }
Expand description
The shared MIME info database.
Implementations§
sourcepub fn new() -> SharedMimeInfo
pub fn new() -> SharedMimeInfo
Creates a new SharedMimeInfo
instance containing all MIME information
under the standard XDG base directories.
sourcepub fn new_for_directory<P: AsRef<Path>>(directory: P) -> SharedMimeInfo
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.
sourcepub fn reload(&mut self) -> bool
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.
sourcepub fn unalias_mime_type(&self, mime_type: &Mime) -> Option<Mime>
pub fn unalias_mime_type(&self, mime_type: &Mime) -> Option<Mime>
Retrieves the MIME type aliased by a MIME type, if any.
sourcepub fn lookup_icon_names(&self, mime_type: &Mime) -> Vec<String>
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.
sourcepub fn lookup_generic_icon_name(&self, mime_type: &Mime) -> Option<String>
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.
sourcepub fn get_parents(&self, mime_type: &Mime) -> Option<Vec<Mime>>
pub fn get_parents(&self, mime_type: &Mime) -> Option<Vec<Mime>>
Retrieves all the parent MIME types associated to mime_type
.
sourcepub fn get_mime_types_from_file_name(&self, file_name: &str) -> Vec<Mime>
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")?]);
sourcepub fn get_mime_type_for_data(&self, data: &[u8]) -> Option<(Mime, u32)>
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.
sourcepub fn mime_type_equal(&self, mime_a: &Mime, mime_b: &Mime) -> bool
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));
sourcepub fn mime_type_subclass(&self, mime_type: &Mime, base: &Mime) -> bool
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));
sourcepub fn guess_mime_type(&self) -> GuessBuilder<'_>
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);