std/io/error/
repr_unpacked.rs

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
5use super::{Custom, ErrorData, ErrorKind, RawOsError, SimpleMessage};
6
7type Inner = ErrorData<Box<Custom>>;
8
9pub(super) struct Repr(Inner);
10
11impl Repr {
12    #[inline]
13    pub(super) fn new_custom(b: Box<Custom>) -> Self {
14        Self(Inner::Custom(b))
15    }
16    #[inline]
17    pub(super) fn new_os(code: RawOsError) -> Self {
18        Self(Inner::Os(code))
19    }
20    #[inline]
21    pub(super) fn new_simple(kind: ErrorKind) -> Self {
22        Self(Inner::Simple(kind))
23    }
24    #[inline]
25    pub(super) const fn new_simple_message(m: &'static SimpleMessage) -> Self {
26        Self(Inner::SimpleMessage(m))
27    }
28    #[inline]
29    pub(super) fn into_data(self) -> ErrorData<Box<Custom>> {
30        self.0
31    }
32    #[inline]
33    pub(super) fn data(&self) -> ErrorData<&Custom> {
34        match &self.0 {
35            Inner::Os(c) => ErrorData::Os(*c),
36            Inner::Simple(k) => ErrorData::Simple(*k),
37            Inner::SimpleMessage(m) => ErrorData::SimpleMessage(*m),
38            Inner::Custom(m) => ErrorData::Custom(&*m),
39        }
40    }
41    #[inline]
42    pub(super) fn data_mut(&mut self) -> ErrorData<&mut Custom> {
43        match &mut self.0 {
44            Inner::Os(c) => ErrorData::Os(*c),
45            Inner::Simple(k) => ErrorData::Simple(*k),
46            Inner::SimpleMessage(m) => ErrorData::SimpleMessage(*m),
47            Inner::Custom(m) => ErrorData::Custom(&mut *m),
48        }
49    }
50}