xref: /linux/rust/pin-init/examples/error.rs (revision 6b3f7af57881f6d6250c6dcc4d910fe8e855a607)
1 // SPDX-License-Identifier: Apache-2.0 OR MIT
2 
3 #![cfg_attr(feature = "alloc", feature(allocator_api))]
4 
5 use core::convert::Infallible;
6 
7 #[cfg(feature = "alloc")]
8 use std::alloc::AllocError;
9 
10 #[derive(Debug)]
11 pub struct Error;
12 
13 impl From<Infallible> for Error {
14     #[inline]
15     fn from(e: Infallible) -> Self {
16         match e {}
17     }
18 }
19 
20 #[cfg(feature = "alloc")]
21 impl From<AllocError> for Error {
22     #[inline]
23     fn from(_: AllocError) -> Self {
24         Self
25     }
26 }
27 
28 #[allow(dead_code)]
29 fn main() {
30     let _ = Error;
31 }
32