]> git.lizzy.rs Git - rust.git/commitdiff
Impl `io::error::repr_bitpacked::Repr::new`
authorJiahao XU <Jiahao_XU@outlook.com>
Wed, 22 Jun 2022 12:01:51 +0000 (22:01 +1000)
committerJiahao XU <Jiahao_XU@outlook.com>
Wed, 22 Jun 2022 12:01:51 +0000 (22:01 +1000)
that accepts `ErrorData<Box<Custom>>`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
library/std/src/io/error/repr_bitpacked.rs

index e80068b46abb9f360f34957c5b3f1ea01c0ca641..292bf4826fd237a3d9dafe63b3d9ae1b5deac1d5 100644 (file)
@@ -132,6 +132,15 @@ unsafe impl Send for Repr {}
 unsafe impl Sync for Repr {}
 
 impl Repr {
+    pub(super) fn new(dat: ErrorData<Box<Custom>>) -> Self {
+        match dat {
+            ErrorData::Os(code) => Self::new_os(code),
+            ErrorData::Simple(kind) => Self::new_simple(kind),
+            ErrorData::SimpleMessage(simple_message) => Self::new_simple_message(simple_message),
+            ErrorData::Custom(b) => Self::new_custom(b),
+        }
+    }
+
     pub(super) fn new_custom(b: Box<Custom>) -> Self {
         let p = Box::into_raw(b).cast::<u8>();
         // Should only be possible if an allocator handed out a pointer with