|
10 | 10 | //! This crate also comes ready with several extension traits for Result that add
|
11 | 11 | //! extra functionality to `Result<T, Void>` and `Result<Void, E>`.
|
12 | 12 | //!
|
| 13 | +//! This can be aliased to core::convert::Infallible using the crates `infallible` feature. |
| 14 | +//! |
13 | 15 |
|
14 |
| -#[cfg(not(feature = "std"))] |
15 |
| -mod coreprovider { |
16 |
| - extern crate core; |
17 |
| - pub use core::{fmt, cmp}; |
18 |
| -} |
| 16 | +/// The empty type for cases which can't occur (aliased to core::convert::Infallible) |
| 17 | +#[cfg(feature = "infallible")] |
| 18 | +pub type Void = core::convert::Infallible; |
19 | 19 |
|
20 |
| -#[cfg(feature = "std")] |
21 |
| -mod coreprovider { |
22 |
| - pub use std::{fmt, cmp, error}; |
23 |
| -} |
| 20 | +#[cfg(not(feature = "infallible"))] |
| 21 | +pub use void::Void; |
24 | 22 |
|
25 |
| -use coreprovider::*; |
| 23 | +#[cfg(not(feature = "infallible"))] |
| 24 | +mod void { |
| 25 | + /// The empty type for cases which can't occur. |
| 26 | + #[derive(Copy)] |
| 27 | + pub enum Void { } |
26 | 28 |
|
27 |
| -/// The empty type for cases which can't occur. |
28 |
| -#[derive(Copy)] |
29 |
| -pub enum Void { } |
30 |
| - |
31 |
| -impl Clone for Void { |
32 |
| - fn clone(&self) -> Void { |
33 |
| - unreachable(*self) |
| 29 | + impl Clone for Void { |
| 30 | + fn clone(&self) -> Void { |
| 31 | + super::unreachable(*self) |
| 32 | + } |
34 | 33 | }
|
35 |
| -} |
36 | 34 |
|
37 |
| -impl fmt::Debug for Void { |
38 |
| - fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result { |
39 |
| - unreachable(*self) |
| 35 | + impl core::fmt::Debug for Void { |
| 36 | + fn fmt(&self, _: &mut core::fmt::Formatter) -> core::fmt::Result { |
| 37 | + super::unreachable(*self) |
| 38 | + } |
40 | 39 | }
|
41 |
| -} |
42 | 40 |
|
43 |
| -impl fmt::Display for Void { |
44 |
| - fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result { |
45 |
| - unreachable(*self) |
| 41 | + impl core::fmt::Display for Void { |
| 42 | + fn fmt(&self, _: &mut core::fmt::Formatter) -> core::fmt::Result { |
| 43 | + super::unreachable(*self) |
| 44 | + } |
46 | 45 | }
|
47 |
| -} |
48 | 46 |
|
49 |
| -impl<T> cmp::PartialEq<T> for Void { |
50 |
| - fn eq(&self, _: &T) -> bool { |
51 |
| - unreachable(*self) |
| 47 | + impl<T> core::cmp::PartialEq<T> for Void { |
| 48 | + fn eq(&self, _: &T) -> bool { |
| 49 | + super::unreachable(*self) |
| 50 | + } |
52 | 51 | }
|
53 |
| -} |
54 | 52 |
|
55 |
| -impl<T> cmp::PartialOrd<T> for Void { |
56 |
| - fn partial_cmp(&self, _: &T) -> Option<cmp::Ordering> { |
57 |
| - unreachable(*self) |
| 53 | + impl<T> core::cmp::PartialOrd<T> for Void { |
| 54 | + fn partial_cmp(&self, _: &T) -> Option<core::cmp::Ordering> { |
| 55 | + super::unreachable(*self) |
| 56 | + } |
58 | 57 | }
|
59 |
| -} |
60 | 58 |
|
61 |
| -#[cfg(feature = "std")] |
62 |
| -impl error::Error for Void { |
63 |
| - fn description(&self) -> &str { |
64 |
| - unreachable(*self) |
65 |
| - } |
| 59 | + #[cfg(feature = "std")] |
| 60 | + impl std::error::Error for Void { |
| 61 | + fn description(&self) -> &str { |
| 62 | + super::unreachable(*self) |
| 63 | + } |
66 | 64 |
|
67 |
| - fn cause(&self) -> Option<&error::Error> { |
68 |
| - unreachable(*self) |
| 65 | + fn cause(&self) -> Option<&(dyn std::error::Error)> { |
| 66 | + super::unreachable(*self) |
| 67 | + } |
69 | 68 | }
|
70 | 69 | }
|
71 | 70 |
|
|
0 commit comments