pub struct Error(/* private fields */);
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§
Source§impl Error
impl Error
Sourcepub const UNSUPPORTED: Error = _
pub const UNSUPPORTED: Error = _
This target/platform is not supported by getrandom
.
Sourcepub const ERRNO_NOT_POSITIVE: Error = _
pub const ERRNO_NOT_POSITIVE: Error = _
The platform-specific errno
returned a non-positive value.
Sourcepub const UNEXPECTED: Error = _
pub const UNEXPECTED: Error = _
Encountered an unexpected situation which should not happen in practice.
Sourcepub const IOS_SEC_RANDOM: Error = _
pub const IOS_SEC_RANDOM: Error = _
Call to CCRandomGenerateBytes
failed
on iOS, tvOS, or waatchOS.
Sourcepub const WINDOWS_RTL_GEN_RANDOM: Error = _
pub const WINDOWS_RTL_GEN_RANDOM: Error = _
Call to Windows RtlGenRandom
failed.
Sourcepub const FAILED_RDRAND: Error = _
pub const FAILED_RDRAND: Error = _
RDRAND instruction failed due to a hardware issue.
Sourcepub const WEB_CRYPTO: Error = _
pub const WEB_CRYPTO: Error = _
The environment does not support the Web Crypto API.
Sourcepub const WEB_GET_RANDOM_VALUES: Error = _
pub const WEB_GET_RANDOM_VALUES: Error = _
Calling Web Crypto API crypto.getRandomValues
failed.
Sourcepub const VXWORKS_RAND_SECURE: Error = _
pub const VXWORKS_RAND_SECURE: Error = _
On VxWorks, call to randSecure
failed (random number generator is not yet initialized).
Sourcepub const NODE_CRYPTO: Error = _
pub const NODE_CRYPTO: Error = _
Node.js does not have the crypto
CommonJS module.
Sourcepub const NODE_RANDOM_FILL_SYNC: Error = _
pub const NODE_RANDOM_FILL_SYNC: Error = _
Calling Node.js function crypto.randomFillSync
failed.
Sourcepub const NODE_ES_MODULE: Error = _
pub const NODE_ES_MODULE: Error = _
Called from an ES module on Node.js. This is unsupported, see: https://docs.rs/getrandom#nodejs-es-module-support.
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§
Source§impl Error for Error
Available on crate feature std
only.
impl Error for Error
std
only.1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<NonZero<u32>> for Error
impl From<NonZero<u32>> for Error
Source§fn from(code: NonZeroU32) -> Self
fn from(code: NonZeroU32) -> Self
impl Copy for Error
impl Eq for Error
impl StructuralPartialEq for Error
Auto Trait Implementations§
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 4 bytes