Skip to content

Commit 7ff3aff

Browse files
committed
Error doc; fix for Solaris
1 parent 9ba1d37 commit 7ff3aff

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/error.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,29 @@ use core::fmt;
1212
#[cfg(not(target_env = "sgx"))]
1313
use std::{io, error};
1414

15+
/// An unknown error.
1516
pub const UNKNOWN_ERROR: Error = Error(unsafe {
1617
NonZeroU32::new_unchecked(0x756e6b6e) // "unkn"
1718
});
1819

20+
/// No generator is available.
1921
pub const UNAVAILABLE_ERROR: Error = Error(unsafe {
2022
NonZeroU32::new_unchecked(0x4e416e61) // "NAna"
2123
});
2224

25+
/// The error type.
26+
///
27+
/// This type is small and no-std compatible.
2328
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
2429
pub struct Error(NonZeroU32);
2530

2631
impl Error {
32+
/// Extract the error code.
33+
///
34+
/// This may equal one of the codes defined in this library or may be a
35+
/// system error code.
36+
///
37+
/// One may attempt to format this error via the `Display` implementation.
2738
pub fn code(&self) -> NonZeroU32 {
2839
self.0
2940
}

src/solaris.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn syscall_getrandom(dest: &mut [u8]) -> Result<(), Error> {
4848
syscall(SYS_GETRANDOM, dest.as_mut_ptr(), dest.len(), 0)
4949
};
5050
if ret == -1 || ret != dest.len() as i64 {
51-
return Err(io::Error::last_os_error().from());
51+
return Err(io::Error::last_os_error().into());
5252
}
5353
Ok(())
5454
}
@@ -75,7 +75,7 @@ pub fn getrandom_os(dest: &mut [u8]) -> Result<(), Error> {
7575
},
7676
}
7777
})
78-
}).map_err(|_| Error::Unknown)
78+
})
7979
}
8080

8181
fn is_getrandom_available() -> bool {

0 commit comments

Comments
 (0)