pub struct Error(_);
Expand description
A small and no_std
compatible error type
The Error::raw_os_error()
will indicate if the error is from the OS, and
if so, which error code the OS gave the application. If such an error is
encountered, please consult with your system documentation.
Internally this type is a NonZeroU32, with certain values reserved for
certain purposes, see Error::INTERNAL_START
and Error::CUSTOM_START
.
If this crate’s "std"
Cargo feature is enabled, then:
getrandom::Error
implementsstd::error::Error
std::io::Error
implementsFrom<getrandom::Error>
.
Implementations
sourceimpl Error
impl Error
sourcepub const UNSUPPORTED: Error = internal_error(0)
pub const UNSUPPORTED: Error = internal_error(0)
This target/platform is not supported by getrandom
.
sourcepub const ERRNO_NOT_POSITIVE: Error = internal_error(1)
pub const ERRNO_NOT_POSITIVE: Error = internal_error(1)
The platform-specific errno
returned a non-positive value.
sourcepub const IOS_SEC_RANDOM: Error = internal_error(3)
pub const IOS_SEC_RANDOM: Error = internal_error(3)
Call to iOS SecRandomCopyBytes
failed.
sourcepub const WINDOWS_RTL_GEN_RANDOM: Error = internal_error(4)
pub const WINDOWS_RTL_GEN_RANDOM: Error = internal_error(4)
Call to Windows RtlGenRandom
failed.
sourcepub const FAILED_RDRAND: Error = internal_error(5)
pub const FAILED_RDRAND: Error = internal_error(5)
RDRAND instruction failed due to a hardware issue.
sourcepub const WEB_CRYPTO: Error = internal_error(7)
pub const WEB_CRYPTO: Error = internal_error(7)
The browser does not have support for self.crypto
.
sourcepub const WEB_GET_RANDOM_VALUES: Error = internal_error(8)
pub const WEB_GET_RANDOM_VALUES: Error = internal_error(8)
The browser does not have support for crypto.getRandomValues
.
sourcepub const VXWORKS_RAND_SECURE: Error = internal_error(11)
pub const VXWORKS_RAND_SECURE: Error = internal_error(11)
On VxWorks, call to randSecure
failed (random number generator is not yet initialized).
sourcepub const NODE_CRYPTO: Error = internal_error(12)
pub const NODE_CRYPTO: Error = internal_error(12)
NodeJS does not have support for the crypto
module.
sourcepub const NODE_RANDOM_FILL_SYNC: Error = internal_error(13)
pub const NODE_RANDOM_FILL_SYNC: Error = internal_error(13)
NodeJS does not have support for crypto.randomFillSync
.
sourcepub const INTERNAL_START: u32 = 2_147_483_648u32
pub const INTERNAL_START: u32 = 2_147_483_648u32
Codes below this point represent OS Errors (i.e. positive i32 values).
Codes at or above this point, but below Error::CUSTOM_START
are
reserved for use by the rand
and getrandom
crates.
sourcepub const CUSTOM_START: u32 = 3_221_225_472u32
pub const CUSTOM_START: u32 = 3_221_225_472u32
Codes at or above this point can be used by users to define their own custom errors.
sourcepub fn raw_os_error(self) -> Option<i32>
pub fn raw_os_error(self) -> Option<i32>
Extract the raw OS error code (if this error came from the OS)
This method is identical to std::io::Error::raw_os_error()
, except
that it works in no_std
contexts. If this method returns None
, the
error value can still be formatted via the Display
implementation.
sourcepub const fn code(self) -> NonZeroU32
pub const fn code(self) -> NonZeroU32
Extract the bare error code.
This code can either come from the underlying OS, or be a custom error.
Use Error::raw_os_error()
to disambiguate.
Trait Implementations
sourceimpl Error for Error
impl Error for Error
1.30.0 · sourcefn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. Read more
sourcefn backtrace(&self) -> Option<&Backtrace>
fn backtrace(&self) -> Option<&Backtrace>
backtrace
)Returns a stack backtrace, if available, of where this error occurred. Read more
1.0.0 · sourcefn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
sourceimpl From<NonZeroU32> for Error
impl From<NonZeroU32> for Error
sourcefn from(code: NonZeroU32) -> Self
fn from(code: NonZeroU32) -> Self
Converts to this type from the input type.
impl Copy for Error
impl Eq for Error
impl StructuralEq for Error
impl StructuralPartialEq for Error
Auto Trait Implementations
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnwindSafe for Error
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more