1pub use std::string::{FromUtf16Error, FromUtf8Error};
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum SliceError {
7 StartOutOfBounds,
9 EndOutOfBounds,
11 EndBeforeStart,
13 StartNotAligned,
15 EndNotAligned,
17}
18
19impl std::fmt::Display for SliceError {
20 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21 match self {
22 Self::StartOutOfBounds => write!(f, "start offset out of bounds"),
23 Self::StartNotAligned => write!(f, "start offset in multibyte UTF-8 sequence"),
24 Self::EndOutOfBounds => write!(f, "end offset out of bounds"),
25 Self::EndNotAligned => write!(f, "end offset in multibyte UTF-8 sequence"),
26 Self::EndBeforeStart => write!(f, "end offset before start offset"),
27 }
28 }
29}
30
31#[test]
32fn slice_error_traits() {
33 use SliceError::*;
34 let errors = [
35 StartOutOfBounds,
36 EndOutOfBounds,
37 EndBeforeStart,
38 StartNotAligned,
39 EndNotAligned,
40 ];
41
42 for error in errors.into_iter() {
43 let new = error.clone();
45 assert_eq!(error, new);
47 format!("{error:?}");
49 format!("{new}");
51 }
52}