shared_mime/runtime/
mod.rs

1//! Load XDG data files at runtime.
2//!
3//! This module provides support for loading the [XDG Shared Mime Info][SMI]
4//! database at runtime from either the XDG directories or from specified
5//! package files.
6//!
7//! This code directly parses the XML from the `packages/` directory, instead of
8//! the pre-parsed files created by `update-mime-info`, for a few reasons:
9//!
10//! - It's pretty fast with [quick_xml].
11//! - There are some weirdnesses in the `globs2` file on my machines around
12//!   case-sensitive matches that are not in the original source.
13//! - The same parsing code can directly load the XML from the
14//!   `shared-mime-info` source repository for embedding.
15//!
16//! [SMI]:
17//!     https://specifications.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html
18mod dirs;
19pub mod mimeinfo;
20pub mod xdg_package;
21mod xdg_parse;
22
23use std::io;
24
25use quick_xml::DeError;
26use thiserror::Error;
27
28pub use dirs::xdg_mime_search_dirs;
29pub use mimeinfo::load_xdg_mime_info;
30pub use xdg_parse::parse_mime_package;
31
32/// Error type for mime-info parse failures.
33#[derive(Error, Debug)]
34pub enum XDGError {
35    #[error("I/O error: {0}")]
36    IO(#[from] io::Error),
37    #[error("XML deserialize error: {0}")]
38    Deserialize(#[from] DeError),
39    #[error("layout error: {0}")]
40    Layout(String),
41}