use std::borrow::Cow; use std::io; use std::sync::Arc; use thiserror::Error; #[derive(Debug, Clone, Error)] #[error(transparent)] pub enum Error { IO(Arc), #[error("Config file does not exist, so a default one was created")] ConfigMissing, #[error("JSON parsing error: {0}")] SerdeJSON(Arc), #[error("TOML parsing error: {0}")] SerdeTOML(#[from] toml::de::Error), RustFmt(Arc), #[error("The element tree contains no matching element")] NonExistentElement, #[error("The file dialog has been closed without selecting a valid option")] DialogClosed, #[error("{0}")] Other(String), } impl From for Error { fn from(value: io::Error) -> Self { Self::IO(Arc::new(value)) } } impl From for Error { fn from(value: serde_json::Error) -> Self { Self::SerdeJSON(Arc::new(value)) } } impl From for Error { fn from(value: rust_format::Error) -> Self { Self::RustFmt(Arc::new(value)) } } impl From<&str> for Error { fn from(value: &str) -> Self { Self::Other(value.to_owned()) } } impl From for Error { fn from(value: String) -> Self { Self::Other(value) } } impl From for String { fn from(value: Error) -> Self { value.to_string() } } impl From for Cow<'static, str> { fn from(value: Error) -> Self { value.to_string().into() } }