use std::str::Utf8Error;
#[allow(clippy::module_name_repetitions)] #[derive(Debug, PartialEq, Eq)]
pub enum PointerError {
#[allow(missing_docs)] Null,
Invalid,
Utf8Error(Utf8Error),
}
impl std::fmt::Display for PointerError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match *self {
Self::Null => {
write!(f, "dereference a null pointer will produce a crash")
}
Self::Invalid => {
write!(f, "dereference a unknown pointer could produce a crash")
}
Self::Utf8Error(..) => {
write!(f, "the provided C string is not a valid UTF-8 string")
}
}
}
}
impl std::error::Error for PointerError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Self::Null | Self::Invalid => None,
Self::Utf8Error(ref e) => Some(e),
}
}
}
impl From<Utf8Error> for PointerError {
fn from(err: Utf8Error) -> Self {
Self::Utf8Error(err)
}
}