use crate::ConstString;
pub type Result<T> = core::result::Result<T, Error>;
#[non_exhaustive]
pub enum Error {
AlreadyExists {
key: ConstString,
},
AlreadyRemapped {
key: ConstString,
remapped: ConstString,
},
Assignment {
key: ConstString,
value: ConstString,
},
CreateRemapping {
source: ConstString,
},
IsLocked {
key: ConstString,
},
NoParent {
key: ConstString,
remapped: ConstString,
},
NoTarget {
key: ConstString,
},
NotFound {
key: ConstString,
},
WrongType {
key: ConstString,
},
Unreachable(ConstString, u32),
}
impl core::error::Error for Error {
}
impl core::fmt::Debug for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::AlreadyExists { key } => write!(f, "AlreadyExists(key: {key})"),
Self::AlreadyRemapped { key, remapped } => {
write!(f, "AlreadyRemapped(key: {key}, remapped: {remapped})")
}
Self::Assignment { key, value } => write!(f, "Assignment(key: {key}, value: {value})"),
Self::CreateRemapping { source } => write!(f, "CreateRemapping(source: {source})"),
Self::IsLocked { key } => write!(f, "Locked(key: {key}"),
Self::NoParent { key, remapped } => write!(f, "NoParent(key: {key}, remapped: {remapped})"),
Self::NoTarget { key } => write!(f, "NoTarget(key: {key})"),
Self::NotFound { key } => write!(f, "NotFound(key: {key})"),
Self::WrongType { key } => write!(f, "WrongType(key: {key})"),
Self::Unreachable(file, line) => write!(f, "Unreachable(file: {file}, line: {line})"),
}
}
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::AlreadyExists { key } => write!(f, "cannot create data with key {key} as they already exist"),
Self::AlreadyRemapped { key, remapped } => {
write!(f, "key {key} is already remapped as {remapped}")
}
Self::Assignment { key, value } => write!(f, "remapping of {key} contains an assignment of {value}"),
Self::CreateRemapping { source } => write!(f, "cannot create a remapping target from {source}"),
Self::IsLocked { key } => write!(f, "the entry {key} is locked"),
Self::NoParent { key, remapped } => write!(f, "remapping of {key} to {remapped} without a parent board"),
Self::NoTarget { key } => write!(f, "no target for {key} defined"),
Self::NotFound { key } => write!(f, "an entry for the key {key} is not existing"),
Self::WrongType { key } => write!(f, "the entry for the key {key} is stored with a different type"),
Self::Unreachable(file, line) => write!(f, "an unexpected error occured in {file} at line {line}"),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
const fn is_normal<T: Sized + Send + Sync>() {}
#[test]
const fn normal_types() {
is_normal::<Error>();
}
}