use std::hash::{Hash, Hasher};
#[derive(Clone, Debug)]
pub struct GenericError(String);
pub type GenericResult<T> = Result<T, GenericError>;
impl GenericError {
pub fn join_many(errs: &[GenericError], separator: &str) -> String {
errs.iter().map(|err| err.0.clone()).collect::<Vec<_>>().join(separator)
}
}
impl std::fmt::Display for GenericError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl std::error::Error for GenericError {}
impl From<String> for GenericError {
fn from(msg: String) -> Self {
Self(msg)
}
}
impl<'a> From<&'a str> for GenericError {
fn from(value: &'a str) -> Self {
Self(value.to_string())
}
}
impl From<Box<dyn std::error::Error>> for GenericError {
fn from(value: Box<dyn std::error::Error>) -> Self {
Self(value.to_string())
}
}
impl From<std::io::Error> for GenericError {
fn from(value: std::io::Error) -> Self {
Self(value.to_string())
}
}
impl PartialEq<Self> for GenericError {
fn eq(&self, other: &Self) -> bool {
self.0.eq(&other.0)
}
}
impl Eq for GenericError {}
impl Hash for GenericError {
fn hash<H: Hasher>(&self, state: &mut H) {
self.0.hash(state);
}
}