@@ -20,6 +20,11 @@ use core::num::NonZeroU32;
20
20
pub struct Error ( NonZeroU32 ) ;
21
21
22
22
impl Error {
23
+ #[ deprecated( since = "0.1.7" ) ]
24
+ pub const UNKNOWN : Error = UNSUPPORTED ;
25
+ #[ deprecated( since = "0.1.7" ) ]
26
+ pub const UNAVAILABLE : Error = UNSUPPORTED ;
27
+
23
28
/// Codes below this point represent OS Errors (i.e. positive i32 values).
24
29
/// Codes at or above this point, but below [`Error::CUSTOM_START`] are
25
30
/// reserved for use by the `rand` and `getrandom` crates.
@@ -111,25 +116,31 @@ impl From<NonZeroU32> for Error {
111
116
}
112
117
}
113
118
114
- /// Internal Error constants
115
- pub ( crate ) const UNSUPPORTED : Error = internal_error ( 0 ) ;
116
- pub ( crate ) const UNKNOWN_IO_ERROR : Error = internal_error ( 1 ) ;
117
- pub ( crate ) const SEC_RANDOM_FAILED : Error = internal_error ( 2 ) ;
118
- pub ( crate ) const RTL_GEN_RANDOM_FAILED : Error = internal_error ( 3 ) ;
119
- pub ( crate ) const FAILED_RDRAND : Error = internal_error ( 4 ) ;
120
- pub ( crate ) const NO_RDRAND : Error = internal_error ( 5 ) ;
121
- pub ( crate ) const BINDGEN_CRYPTO_UNDEF : Error = internal_error ( 6 ) ;
122
- pub ( crate ) const BINDGEN_GRV_UNDEF : Error = internal_error ( 7 ) ;
123
- pub ( crate ) const STDWEB_NO_RNG : Error = internal_error ( 8 ) ;
124
- pub ( crate ) const STDWEB_RNG_FAILED : Error = internal_error ( 9 ) ;
125
-
126
- const fn internal_error ( n : u16 ) -> Error {
127
- Error ( unsafe { NonZeroU32 :: new_unchecked ( Error :: INTERNAL_START + n as u32 ) } )
119
+ // TODO: Convert to a function when min_version >= 1.33
120
+ macro_rules! internal_error {
121
+ ( $code: expr) => { {
122
+ let n: u16 = $code;
123
+ Error ( unsafe { NonZeroU32 :: new_unchecked( Error :: INTERNAL_START + n as u32 ) } )
124
+ } } ;
128
125
}
129
126
127
+ /// Internal Error constants
128
+ pub ( crate ) const UNSUPPORTED : Error = internal_error ! ( 0 ) ;
129
+ pub ( crate ) const ERRNO_NOT_POSITIVE : Error = internal_error ! ( 1 ) ;
130
+ pub ( crate ) const UNKNOWN_IO_ERROR : Error = internal_error ! ( 2 ) ;
131
+ pub ( crate ) const SEC_RANDOM_FAILED : Error = internal_error ! ( 3 ) ;
132
+ pub ( crate ) const RTL_GEN_RANDOM_FAILED : Error = internal_error ! ( 4 ) ;
133
+ pub ( crate ) const FAILED_RDRAND : Error = internal_error ! ( 5 ) ;
134
+ pub ( crate ) const NO_RDRAND : Error = internal_error ! ( 6 ) ;
135
+ pub ( crate ) const BINDGEN_CRYPTO_UNDEF : Error = internal_error ! ( 7 ) ;
136
+ pub ( crate ) const BINDGEN_GRV_UNDEF : Error = internal_error ! ( 8 ) ;
137
+ pub ( crate ) const STDWEB_NO_RNG : Error = internal_error ! ( 9 ) ;
138
+ pub ( crate ) const STDWEB_RNG_FAILED : Error = internal_error ! ( 10 ) ;
139
+
130
140
fn internal_desc ( error : Error ) -> Option < & ' static str > {
131
141
match error {
132
142
UNSUPPORTED => Some ( "getrandom: this target is not supported" ) ,
143
+ ERRNO_NOT_POSITIVE => Some ( "errno: did not return a positive value" ) ,
133
144
UNKNOWN_IO_ERROR => Some ( "Unknown std::io::Error" ) ,
134
145
SEC_RANDOM_FAILED => Some ( "SecRandomCopyBytes: call failed" ) ,
135
146
RTL_GEN_RANDOM_FAILED => Some ( "RtlGenRandom: call failed" ) ,
0 commit comments