use std::fmt::{Display, Formatter};
#[derive(Debug)]
pub struct Error(String);
impl Error {
pub(crate) fn null() -> Self {
Self("null pointer".into())
}
pub(crate) fn nul_terminated() -> Self {
Self("string is not nul terminated".into())
}
}
impl From<String> for Error {
fn from(s: String) -> Self {
Self(s)
}
}
impl From<&str> for Error {
fn from(s: &str) -> Self {
Self(s.to_string())
}
}
impl From<std::fmt::Error> for Error {
fn from(e: std::fmt::Error) -> Self {
Self(e.to_string())
}
}
impl From<std::str::Utf8Error> for Error {
fn from(e: std::str::Utf8Error) -> Self {
Self(e.to_string())
}
}
impl From<std::string::FromUtf8Error> for Error {
fn from(e: std::string::FromUtf8Error) -> Self {
Self(e.to_string())
}
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl std::error::Error for Error {}