shared_mime/
error.rs

1//! Shared MIME DB errors.
2
3use std::io;
4
5use thiserror::Error;
6
7/// Errors that can occur when loading the MIME data.
8#[derive(Debug, Error)]
9pub enum LoadError {
10    #[cfg(feature = "xdg-runtime")]
11    #[error("XDG load error: {0}")]
12    XDG(#[from] crate::runtime::XDGError),
13
14    #[error("MIME database unavailable")]
15    Unavailable,
16
17    #[error("load error: {0}")]
18    Generic(String),
19}
20
21/// Create a load error with the specified message.
22pub fn load_error<S: AsRef<str>>(msg: S) -> LoadError {
23    LoadError::Generic(msg.as_ref().into())
24}
25
26/// Errors that can occur when querying the MIME data.
27#[derive(Debug, Error)]
28pub enum QueryError {
29    #[error("load error: {0}")]
30    Generic(String),
31    #[error("I/O error: {0}")]
32    IO(#[from] io::Error),
33}
34
35/// Create a load error with the specified message.
36pub fn query_error<S: AsRef<str>>(msg: S) -> QueryError {
37    QueryError::Generic(msg.as_ref().into())
38}