1use core::{error::Error as CoreError, fmt};
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14#[non_exhaustive]
15pub enum Error {
16 Full,
18 OutOfBounds,
20 InvalidLen,
24}
25
26impl fmt::Display for Error {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 match self {
29 Self::Full => f.write_str("capacity exceeded"),
30 Self::OutOfBounds => f.write_str("index out of bounds"),
31 Self::InvalidLen => f.write_str("invalid length"),
32 }
33 }
34}
35
36impl CoreError for Error {}
37
38#[cfg(test)]
39mod tests {
40 use crate::Error;
42 use alloc::string::{String, ToString};
43 use core::error::Error as CoreError;
44
45 fn takes_error(e: &dyn CoreError) -> String {
46 e.to_string()
47 }
48
49 #[test]
50 fn test_error_is_core_error() {
51 let s = takes_error(&Error::OutOfBounds);
52 assert!(s.contains("out of bounds"));
53 }
54}