]> git.lizzy.rs Git - rust.git/blob - library/std/src/io/error/repr_unpacked.rs
Rollup merge of #93613 - crlf0710:rename_to_async_iter, r=yaahc
[rust.git] / library / std / src / 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
5 use super::{Custom, ErrorData, ErrorKind, 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     pub(super) fn new_custom(b: Box<Custom>) -> Self {
14         Self(Inner::Custom(b))
15     }
16     #[inline]
17     pub(super) fn new_os(code: i32) -> 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 }