@@ -19,13 +19,33 @@ use core::num::NonZeroU32;
19
19
#[ derive( Copy , Clone , Eq , PartialEq ) ]
20
20
pub struct Error ( NonZeroU32 ) ;
21
21
22
+ // TODO: Convert to a function when min_version >= 1.33
23
+ macro_rules! internal_error {
24
+ ( $n: expr) => {
25
+ Error ( unsafe { NonZeroU32 :: new_unchecked( Error :: INTERNAL_START + $n as u16 as u32 ) } )
26
+ } ;
27
+ }
28
+
22
29
impl Error {
30
+ /// Error constants
31
+ pub ( crate ) const UNSUPPORTED : Error = internal_error ! ( 0 ) ;
32
+ pub ( crate ) const ERRNO_NOT_POSITIVE : Error = internal_error ! ( 1 ) ;
33
+ pub ( crate ) const UNKNOWN_IO_ERROR : Error = internal_error ! ( 2 ) ;
34
+ pub ( crate ) const SEC_RANDOM_FAILED : Error = internal_error ! ( 3 ) ;
35
+ pub ( crate ) const RTL_GEN_RANDOM_FAILED : Error = internal_error ! ( 4 ) ;
36
+ pub ( crate ) const FAILED_RDRAND : Error = internal_error ! ( 5 ) ;
37
+ pub ( crate ) const NO_RDRAND : Error = internal_error ! ( 6 ) ;
38
+ pub ( crate ) const BINDGEN_CRYPTO_UNDEF : Error = internal_error ! ( 7 ) ;
39
+ pub ( crate ) const BINDGEN_GRV_UNDEF : Error = internal_error ! ( 8 ) ;
40
+ pub ( crate ) const STDWEB_NO_RNG : Error = internal_error ! ( 9 ) ;
41
+ pub ( crate ) const STDWEB_RNG_FAILED : Error = internal_error ! ( 10 ) ;
42
+
23
43
#[ deprecated( since = "0.1.7" ) ]
24
44
/// Unknown error.
25
- pub const UNKNOWN : Error = UNSUPPORTED ;
45
+ pub const UNKNOWN : Error = Error :: UNSUPPORTED ;
26
46
#[ deprecated( since = "0.1.7" ) ]
27
47
/// System entropy source is unavailable.
28
- pub const UNAVAILABLE : Error = UNSUPPORTED ;
48
+ pub const UNAVAILABLE : Error = Error :: UNSUPPORTED ;
29
49
30
50
/// Codes below this point represent OS Errors (i.e. positive i32 values).
31
51
/// Codes at or above this point, but below [`Error::CUSTOM_START`] are
@@ -126,39 +146,19 @@ impl From<NonZeroU32> for Error {
126
146
}
127
147
}
128
148
129
- // TODO: Convert to a function when min_version >= 1.33
130
- macro_rules! internal_error {
131
- ( $n: expr) => {
132
- Error ( unsafe { NonZeroU32 :: new_unchecked( Error :: INTERNAL_START + $n as u16 as u32 ) } )
133
- } ;
134
- }
135
-
136
- /// Internal Error constants
137
- pub ( crate ) const UNSUPPORTED : Error = internal_error ! ( 0 ) ;
138
- pub ( crate ) const ERRNO_NOT_POSITIVE : Error = internal_error ! ( 1 ) ;
139
- pub ( crate ) const UNKNOWN_IO_ERROR : Error = internal_error ! ( 2 ) ;
140
- pub ( crate ) const SEC_RANDOM_FAILED : Error = internal_error ! ( 3 ) ;
141
- pub ( crate ) const RTL_GEN_RANDOM_FAILED : Error = internal_error ! ( 4 ) ;
142
- pub ( crate ) const FAILED_RDRAND : Error = internal_error ! ( 5 ) ;
143
- pub ( crate ) const NO_RDRAND : Error = internal_error ! ( 6 ) ;
144
- pub ( crate ) const BINDGEN_CRYPTO_UNDEF : Error = internal_error ! ( 7 ) ;
145
- pub ( crate ) const BINDGEN_GRV_UNDEF : Error = internal_error ! ( 8 ) ;
146
- pub ( crate ) const STDWEB_NO_RNG : Error = internal_error ! ( 9 ) ;
147
- pub ( crate ) const STDWEB_RNG_FAILED : Error = internal_error ! ( 10 ) ;
148
-
149
149
fn internal_desc ( error : Error ) -> Option < & ' static str > {
150
150
match error {
151
- UNSUPPORTED => Some ( "getrandom: this target is not supported" ) ,
152
- ERRNO_NOT_POSITIVE => Some ( "errno: did not return a positive value" ) ,
153
- UNKNOWN_IO_ERROR => Some ( "Unknown std::io::Error" ) ,
154
- SEC_RANDOM_FAILED => Some ( "SecRandomCopyBytes: call failed" ) ,
155
- RTL_GEN_RANDOM_FAILED => Some ( "RtlGenRandom: call failed" ) ,
156
- FAILED_RDRAND => Some ( "RDRAND: failed multiple times: CPU issue likely" ) ,
157
- NO_RDRAND => Some ( "RDRAND: instruction not supported" ) ,
158
- BINDGEN_CRYPTO_UNDEF => Some ( "wasm-bindgen: self.crypto is undefined" ) ,
159
- BINDGEN_GRV_UNDEF => Some ( "wasm-bindgen: crypto.getRandomValues is undefined" ) ,
160
- STDWEB_NO_RNG => Some ( "stdweb: no randomness source available" ) ,
161
- STDWEB_RNG_FAILED => Some ( "stdweb: failed to get randomness" ) ,
151
+ Error :: UNSUPPORTED => Some ( "getrandom: this target is not supported" ) ,
152
+ Error :: ERRNO_NOT_POSITIVE => Some ( "errno: did not return a positive value" ) ,
153
+ Error :: UNKNOWN_IO_ERROR => Some ( "Unknown std::io::Error" ) ,
154
+ Error :: SEC_RANDOM_FAILED => Some ( "SecRandomCopyBytes: call failed" ) ,
155
+ Error :: RTL_GEN_RANDOM_FAILED => Some ( "RtlGenRandom: call failed" ) ,
156
+ Error :: FAILED_RDRAND => Some ( "RDRAND: failed multiple times: CPU issue likely" ) ,
157
+ Error :: NO_RDRAND => Some ( "RDRAND: instruction not supported" ) ,
158
+ Error :: BINDGEN_CRYPTO_UNDEF => Some ( "wasm-bindgen: self.crypto is undefined" ) ,
159
+ Error :: BINDGEN_GRV_UNDEF => Some ( "wasm-bindgen: crypto.getRandomValues is undefined" ) ,
160
+ Error :: STDWEB_NO_RNG => Some ( "stdweb: no randomness source available" ) ,
161
+ Error :: STDWEB_RNG_FAILED => Some ( "stdweb: failed to get randomness" ) ,
162
162
_ => None ,
163
163
}
164
164
}
0 commit comments