@@ -24,6 +24,7 @@ const BLOCK_SIZE: u32 = 1 << 16;
24
24
25
25
impl Error {
26
26
/// Create a new error from a raw OS error number (errno).
27
+ #[ inline]
27
28
pub fn from_os_error ( errno : i32 ) -> Self {
28
29
assert ! ( errno > 0 ) ;
29
30
Self ( NonZeroU32 :: new ( errno as u32 ) . unwrap ( ) )
@@ -32,9 +33,10 @@ impl Error {
32
33
/// Crate a custom error in the provided block (group of 2^16 error codes).
33
34
/// The provided block must not be negative, and block 0 is reserved for
34
35
/// custom errors in the `getrandom` crate.
36
+ #[ inline]
35
37
pub fn custom_error ( block : i16 , code : u16 ) -> Self {
36
38
assert ! ( block >= 0 ) ;
37
- let n = CUSTOM_START + ( block as u32 ) * BLOCK_SIZE + ( code as u32 ) ;
39
+ let n = CUSTOM_START + ( block as u16 as u32 ) * BLOCK_SIZE + ( code as u32 ) ;
38
40
Self ( NonZeroU32 :: new ( n) . unwrap ( ) )
39
41
}
40
42
@@ -43,6 +45,7 @@ impl Error {
43
45
/// This method is identical to `std::io::Error::raw_os_error()`, except
44
46
/// that it works in `no_std` contexts. If this method returns `None`, the
45
47
/// error value can still be formatted via the `Diplay` implementation.
48
+ #[ inline]
46
49
pub fn raw_os_error ( & self ) -> Option < i32 > {
47
50
self . try_os_error ( ) . ok ( )
48
51
}
@@ -51,6 +54,7 @@ impl Error {
51
54
///
52
55
/// This code can either come from the underlying OS, or be a custom error.
53
56
/// Use [`raw_os_error()`] to disambiguate.
57
+ #[ inline]
54
58
pub fn code ( & self ) -> NonZeroU32 {
55
59
self . 0
56
60
}
0 commit comments