imessage_database/error/
typedstream.rs1use std::{
6 array::TryFromSliceError,
7 fmt::{Display, Formatter, Result},
8 str::Utf8Error,
9};
10
11#[derive(Debug)]
13pub enum TypedStreamError {
14 OutOfBounds(usize, usize),
17 InvalidHeader,
19 SliceError(TryFromSliceError),
21 StringParseError(Utf8Error),
23 InvalidArray,
25 InvalidPointer(usize),
27}
28
29impl std::error::Error for TypedStreamError {}
30
31impl Display for TypedStreamError {
32 fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
33 match self {
34 TypedStreamError::OutOfBounds(idx, len) => {
35 write!(fmt, "Index {idx:x} is outside of range {len:x}!")
36 }
37 TypedStreamError::InvalidHeader => write!(fmt, "Invalid typedstream header!"),
38 TypedStreamError::SliceError(why) => {
39 write!(fmt, "Unable to slice source stream: {why}")
40 }
41 TypedStreamError::StringParseError(why) => write!(fmt, "Failed to parse string: {why}"),
42 TypedStreamError::InvalidArray => write!(fmt, "Failed to parse array data"),
43 TypedStreamError::InvalidPointer(why) => write!(fmt, "Failed to parse pointer: {why}"),
44 }
45 }
46}