std/io/error/
repr_unpacked.rs1use 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(dat: ErrorData<Box<Custom>>) -> Self {
14 Self(dat)
15 }
16 pub(super) fn new_custom(b: Box<Custom>) -> Self {
17 Self(Inner::Custom(b))
18 }
19 #[inline]
20 pub(super) fn new_os(code: RawOsError) -> Self {
21 Self(Inner::Os(code))
22 }
23 #[inline]
24 pub(super) fn new_simple(kind: ErrorKind) -> Self {
25 Self(Inner::Simple(kind))
26 }
27 #[inline]
28 pub(super) const fn new_simple_message(m: &'static SimpleMessage) -> Self {
29 Self(Inner::SimpleMessage(m))
30 }
31 #[inline]
32 pub(super) fn into_data(self) -> ErrorData<Box<Custom>> {
33 self.0
34 }
35 #[inline]
36 pub(super) fn data(&self) -> ErrorData<&Custom> {
37 match &self.0 {
38 Inner::Os(c) => ErrorData::Os(*c),
39 Inner::Simple(k) => ErrorData::Simple(*k),
40 Inner::SimpleMessage(m) => ErrorData::SimpleMessage(*m),
41 Inner::Custom(m) => ErrorData::Custom(&*m),
42 }
43 }
44 #[inline]
45 pub(super) fn data_mut(&mut self) -> ErrorData<&mut Custom> {
46 match &mut self.0 {
47 Inner::Os(c) => ErrorData::Os(*c),
48 Inner::Simple(k) => ErrorData::Simple(*k),
49 Inner::SimpleMessage(m) => ErrorData::SimpleMessage(*m),
50 Inner::Custom(m) => ErrorData::Custom(&mut *m),
51 }
52 }
53}