#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct AppInfo {
pub name: &'static str,
pub author: &'static str,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub enum AppDataType {
UserConfig,
UserData,
UserCache,
SharedData,
SharedConfig,
}
impl AppDataType {
#[must_use]
pub fn is_shared(&self) -> bool {
use crate::AppDataType::{SharedConfig, SharedData};
matches!(self, SharedData | SharedConfig)
}
}
const ERR_NOT_SUPPORTED: &str = "App data directories not supported";
const ERR_INVALID_APP_INFO: &str = "Invalid app name or author";
#[derive(Debug)]
pub enum AppDirsError {
Io(std::io::Error),
NotSupported,
InvalidAppInfo,
}
impl std::fmt::Display for AppDirsError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
use crate::AppDirsError::*;
match *self {
Io(ref e) => std::fmt::Display::fmt(e, f),
NotSupported => f.write_str(ERR_NOT_SUPPORTED),
InvalidAppInfo => f.write_str(ERR_INVALID_APP_INFO),
}
}
}
impl std::error::Error for AppDirsError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use crate::AppDirsError::*;
match *self {
Io(ref e) => Some(e),
NotSupported => None,
InvalidAppInfo => None,
}
}
}
impl From<std::io::Error> for AppDirsError {
fn from(e: std::io::Error) -> Self {
AppDirsError::Io(e)
}
}