use std::fmt::{self, Display};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct IndexGreaterThanLenError {
use_check_to_instantiate: (),
}
impl IndexGreaterThanLenError {
pub fn check(index: usize, len: usize) -> Result<(), Self> {
if index > len {
Err(IndexGreaterThanLenError {
use_check_to_instantiate: (),
})
} else {
Ok(())
}
}
}
impl Display for IndexGreaterThanLenError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{self:#?}:/n The index was greater than the len.")
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_index_greater_than_len_error() {
assert!(IndexGreaterThanLenError::check(5, 5).is_ok());
assert!(IndexGreaterThanLenError::check(6, 5).is_err());
}
}