Skip to content

Commit

Permalink
Fixed formatting, inline, and conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
josephlr committed Jul 9, 2019
1 parent a356105 commit 0931408
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const BLOCK_SIZE: u32 = 1 << 16;

impl Error {
/// Create a new error from a raw OS error number (errno).
#[inline]
pub fn from_os_error(errno: i32) -> Self {
assert!(errno > 0);
Self(NonZeroU32::new(errno as u32).unwrap())
Expand All @@ -32,9 +33,10 @@ impl Error {
/// Crate a custom error in the provided block (group of 2^16 error codes).
/// The provided block must not be negative, and block 0 is reserved for
/// custom errors in the `getrandom` crate.
#[inline]
pub fn custom_error(block: i16, code: u16) -> Self {
assert!(block >= 0);
let n = CUSTOM_START + (block as u32) * BLOCK_SIZE + (code as u32);
let n = CUSTOM_START + (block as u16 as u32) * BLOCK_SIZE + (code as u32);
Self(NonZeroU32::new(n).unwrap())
}

Expand All @@ -43,6 +45,7 @@ impl Error {
/// 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 `Diplay` implementation.
#[inline]
pub fn raw_os_error(&self) -> Option<i32> {
self.try_os_error().ok()
}
Expand All @@ -51,6 +54,7 @@ impl Error {
///
/// This code can either come from the underlying OS, or be a custom error.
/// Use [`raw_os_error()`] to disambiguate.
#[inline]
pub fn code(&self) -> NonZeroU32 {
self.0
}
Expand Down
2 changes: 1 addition & 1 deletion src/linux_android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

//! Implementation for Linux / Android
use crate::util::LazyBool;
use crate::util_libc::{sys_fill_exact, last_os_error};
use crate::util_libc::{last_os_error, sys_fill_exact};
use crate::{use_file, Error};

pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
Expand Down

0 comments on commit 0931408

Please sign in to comment.