1 //! This is a fairly simple unpacked error representation that's used on 2 //! non-64bit targets, where the packed 64 bit representation wouldn't work, and 3 //! would have no benefit. 4 5 use super::{Custom, ErrorData, ErrorKind, RawOsError, SimpleMessage}; 6 use alloc::boxed::Box; 7 8 type Inner = ErrorData<Box<Custom>>; 9 10 pub(super) struct Repr(Inner); 11 12 impl Repr { 13 #[inline] 14 pub(super) fn new(dat: ErrorData<Box<Custom>>) -> Self { 15 Self(dat) 16 } 17 pub(super) fn new_custom(b: Box<Custom>) -> Self { 18 Self(Inner::Custom(b)) 19 } 20 #[inline] 21 pub(super) fn new_os(code: RawOsError) -> Self { 22 Self(Inner::Os(code)) 23 } 24 #[inline] 25 pub(super) fn new_simple(kind: ErrorKind) -> Self { 26 Self(Inner::Simple(kind)) 27 } 28 #[inline] 29 pub(super) const fn new_simple_message(m: &'static SimpleMessage) -> Self { 30 Self(Inner::SimpleMessage(m)) 31 } 32 #[inline] 33 pub(super) fn into_data(self) -> ErrorData<Box<Custom>> { 34 self.0 35 } 36 #[inline] 37 pub(super) fn data(&self) -> ErrorData<&Custom> { 38 match &self.0 { 39 Inner::Os(c) => ErrorData::Os(*c), 40 Inner::Simple(k) => ErrorData::Simple(*k), 41 Inner::SimpleMessage(m) => ErrorData::SimpleMessage(*m), 42 Inner::Custom(m) => ErrorData::Custom(&*m), 43 } 44 } 45 #[inline] 46 pub(super) fn data_mut(&mut self) -> ErrorData<&mut Custom> { 47 match &mut self.0 { 48 Inner::Os(c) => ErrorData::Os(*c), 49 Inner::Simple(k) => ErrorData::Simple(*k), 50 Inner::SimpleMessage(m) => ErrorData::SimpleMessage(*m), 51 Inner::Custom(m) => ErrorData::Custom(&mut *m), 52 } 53 } 54 } 55