use core::{error::Error as CoreError, fmt};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
Full,
OutOfBounds,
InvalidLen,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Full => f.write_str("capacity exceeded"),
Self::OutOfBounds => f.write_str("index out of bounds"),
Self::InvalidLen => f.write_str("invalid length"),
}
}
}
impl CoreError for Error {}
#[cfg(test)]
mod tests {
use crate::Error;
use alloc::string::{String, ToString};
use core::error::Error as CoreError;
fn takes_error(e: &dyn CoreError) -> String {
e.to_string()
}
#[test]
fn test_error_is_core_error() {
let s = takes_error(&Error::OutOfBounds);
assert!(s.contains("out of bounds"));
}
}