1use crate::{ArchivePointee, Fallible};
4use bytecheck::CheckBytes;
5use core::fmt;
6#[cfg(feature = "std")]
7use std::error::Error;
8
9#[derive(Debug)]
11pub enum OwnedPointerError<T, R, C> {
12 PointerCheckBytesError(T),
14 ValueCheckBytesError(R),
16 ContextError(C),
18}
19
20impl<T, R, C> fmt::Display for OwnedPointerError<T, R, C>
21where
22 T: fmt::Display,
23 R: fmt::Display,
24 C: fmt::Display,
25{
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 match self {
28 OwnedPointerError::PointerCheckBytesError(e) => e.fmt(f),
29 OwnedPointerError::ValueCheckBytesError(e) => e.fmt(f),
30 OwnedPointerError::ContextError(e) => e.fmt(f),
31 }
32 }
33}
34
35#[cfg(feature = "std")]
36impl<T, R, C> Error for OwnedPointerError<T, R, C>
37where
38 T: Error + 'static,
39 R: Error + 'static,
40 C: Error + 'static,
41{
42 fn source(&self) -> Option<&(dyn Error + 'static)> {
43 match self {
44 OwnedPointerError::PointerCheckBytesError(e) => Some(e as &dyn Error),
45 OwnedPointerError::ValueCheckBytesError(e) => Some(e as &dyn Error),
46 OwnedPointerError::ContextError(e) => Some(e as &dyn Error),
47 }
48 }
49}
50
51pub type CheckOwnedPointerError<T, C> = OwnedPointerError<
53 <<T as ArchivePointee>::ArchivedMetadata as CheckBytes<C>>::Error,
54 <T as CheckBytes<C>>::Error,
55 <C as Fallible>::Error,
56>;