@@ -20,6 +20,11 @@ use core::num::NonZeroU32;
2020pub struct Error ( NonZeroU32 ) ;
2121
2222impl 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+
2328 /// Codes below this point represent OS Errors (i.e. positive i32 values).
2429 /// Codes at or above this point, but below [`Error::CUSTOM_START`] are
2530 /// reserved for use by the `rand` and `getrandom` crates.
@@ -111,25 +116,31 @@ impl From<NonZeroU32> for Error {
111116 }
112117}
113118
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+ } } ;
128125}
129126
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+
130140fn internal_desc ( error : Error ) -> Option < & ' static str > {
131141 match error {
132142 UNSUPPORTED => Some ( "getrandom: this target is not supported" ) ,
143+ ERRNO_NOT_POSITIVE => Some ( "errno: did not return a positive value" ) ,
133144 UNKNOWN_IO_ERROR => Some ( "Unknown std::io::Error" ) ,
134145 SEC_RANDOM_FAILED => Some ( "SecRandomCopyBytes: call failed" ) ,
135146 RTL_GEN_RANDOM_FAILED => Some ( "RtlGenRandom: call failed" ) ,
0 commit comments