use core::{
clone::Clone,
cmp::{Eq, Ord, PartialEq, PartialOrd},
fmt::{Debug, Display, Formatter},
hash::Hash,
marker::Copy,
};
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct InsufficientCapacityError;
impl Display for InsufficientCapacityError {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "arraystring insufficient capacity")
}
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl std::error::Error for InsufficientCapacityError {}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum InsertError {
InvalidIndex,
InsufficientCapacity,
}
impl Display for InsertError {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
let s = match *self {
InsertError::InvalidIndex => "invalid index",
InsertError::InsufficientCapacity => "insufficient capacity",
};
write!(f, "arraystring insert error: {}", s)
}
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl std::error::Error for InsertError {}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct IndexError;
impl core::fmt::Display for IndexError {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(
f,
"arraystring index error: index is out of bounds or doesn't lie on character boundary"
)
}
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl std::error::Error for IndexError {}
#[cfg(all(test, feature = "std"))]
mod testing {
use super::*;
#[test]
fn insufficient_capacity_error_display() {
let e = InsufficientCapacityError {};
let s = format!("{}", e);
assert_eq!(s, "arraystring insufficient capacity");
}
#[test]
fn insert_error_display() {
let e = InsertError::InvalidIndex;
let s = format!("{}", e);
assert_eq!(s, "arraystring insert error: invalid index");
let e = InsertError::InsufficientCapacity;
let s = format!("{}", e);
assert_eq!(s, "arraystring insert error: insufficient capacity");
}
#[test]
fn index_error() {
let e = IndexError {};
let s = format!("{}", e);
assert_eq!(
s,
"arraystring index error: index is out of bounds or doesn't lie on character boundary"
);
}
}