Skip to content

Commit 8679ccf

Browse files
committed
Run Rustfmt on entire repo
1 parent 6a93183 commit 8679ccf

21 files changed

Lines changed: 119 additions & 90 deletions

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ matrix:
2828
install:
2929
- rustup component add rustfmt
3030
script:
31-
- cargo fmt --all -- src/*.rs --check
31+
- cargo fmt --all -- */*.rs --check
3232

3333
- rust: nightly
3434
os: linux

benches/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#![feature(test)]
2-
extern crate test;
32
extern crate getrandom;
3+
extern crate test;
44

55
#[bench]
66
fn bench_64(b: &mut test::Bencher) {
77
let mut buf = [0u8; 64];
88
b.iter(|| {
99
getrandom::getrandom(&mut buf[..]).unwrap();
10-
test::black_box(&buf);
10+
test::black_box(&buf);
1111
});
1212
b.bytes = buf.len() as u64;
1313
}
@@ -17,8 +17,7 @@ fn bench_65536(b: &mut test::Bencher) {
1717
let mut buf = [0u8; 65536];
1818
b.iter(|| {
1919
getrandom::getrandom(&mut buf[..]).unwrap();
20-
test::black_box(&buf);
20+
test::black_box(&buf);
2121
});
2222
b.bytes = buf.len() as u64;
2323
}
24-

src/cloudabi.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
// except according to those terms.
88

99
//! Implementation for CloudABI
10-
use core::num::NonZeroU32;
1110
use crate::Error;
11+
use core::num::NonZeroU32;
1212

1313
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
1414
let errno = unsafe { cloudabi::random_get(dest) };
@@ -22,4 +22,6 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
2222
}
2323

2424
#[inline(always)]
25-
pub fn error_msg_inner(_: NonZeroU32) -> Option<&'static str> { None }
25+
pub fn error_msg_inner(_: NonZeroU32) -> Option<&'static str> {
26+
None
27+
}

src/dummy.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88

99
//! A dummy implementation for unsupported targets which always returns
1010
//! `Err(Error::UNAVAILABLE)`
11-
use core::num::NonZeroU32;
1211
use crate::Error;
12+
use core::num::NonZeroU32;
1313

1414
pub fn getrandom_inner(_: &mut [u8]) -> Result<(), Error> {
1515
error!("no support for this platform");
1616
Err(Error::UNAVAILABLE)
1717
}
1818

1919
#[inline(always)]
20-
pub fn error_msg_inner(_: NonZeroU32) -> Option<&'static str> { None }
20+
pub fn error_msg_inner(_: NonZeroU32) -> Option<&'static str> {
21+
None
22+
}

src/error.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
8-
use core::num::NonZeroU32;
98
use core::convert::From;
109
use core::fmt;
10+
use core::num::NonZeroU32;
1111

1212
// A randomly-chosen 24-bit prefix for our codes
1313
pub(crate) const CODE_PREFIX: u32 = 0x57f4c500;
@@ -22,14 +22,10 @@ pub struct Error(pub(crate) NonZeroU32);
2222

2323
impl Error {
2424
/// An unknown error.
25-
pub const UNKNOWN: Error = Error(unsafe {
26-
NonZeroU32::new_unchecked(CODE_UNKNOWN)
27-
});
25+
pub const UNKNOWN: Error = Error(unsafe { NonZeroU32::new_unchecked(CODE_UNKNOWN) });
2826

2927
/// No generator is available.
30-
pub const UNAVAILABLE: Error = Error(unsafe {
31-
NonZeroU32::new_unchecked(CODE_UNAVAILABLE)
32-
});
28+
pub const UNAVAILABLE: Error = Error(unsafe { NonZeroU32::new_unchecked(CODE_UNAVAILABLE) });
3329

3430
/// Extract the error code.
3531
///
@@ -48,7 +44,7 @@ impl Error {
4844
match *self {
4945
Error::UNKNOWN => Some("getrandom: unknown error"),
5046
Error::UNAVAILABLE => Some("getrandom: unavailable"),
51-
_ => None
47+
_ => None,
5248
}
5349
}
5450
}
@@ -80,8 +76,8 @@ impl From<NonZeroU32> for Error {
8076

8177
#[cfg(test)]
8278
mod tests {
83-
use core::mem::size_of;
8479
use super::Error;
80+
use core::mem::size_of;
8581

8682
#[test]
8783
fn test_size() {

src/error_impls.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
// except according to those terms.
88
extern crate std;
99

10-
use std::{io, error};
10+
use crate::error::Error;
1111
use core::convert::From;
1212
use core::num::NonZeroU32;
13-
use crate::error::Error;
13+
use std::{error, io};
1414

1515
impl From<io::Error> for Error {
1616
fn from(err: io::Error) -> Self {
@@ -31,4 +31,4 @@ impl From<Error> for io::Error {
3131
}
3232
}
3333

34-
impl error::Error for Error { }
34+
impl error::Error for Error {}

src/freebsd.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
extern crate std;
1111

1212
use crate::Error;
13-
use std::io;
14-
use core::ptr;
1513
use core::num::NonZeroU32;
14+
use core::ptr;
15+
use std::io;
1616

1717
fn kern_arnd(buf: &mut [u8]) -> Result<usize, Error> {
1818
static MIB: [libc::c_int; 2] = [libc::CTL_KERN, libc::KERN_ARND];
@@ -43,4 +43,6 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
4343
}
4444

4545
#[inline(always)]
46-
pub fn error_msg_inner(_: NonZeroU32) -> Option<&'static str> { None }
46+
pub fn error_msg_inner(_: NonZeroU32) -> Option<&'static str> {
47+
None
48+
}

src/fuchsia.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
// except according to those terms.
88

99
//! Implementation for Fuchsia Zircon
10-
use core::num::NonZeroU32;
1110
use crate::Error;
11+
use core::num::NonZeroU32;
1212

1313
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
1414
fuchsia_cprng::cprng_draw(dest);
1515
Ok(())
1616
}
1717

1818
#[inline(always)]
19-
pub fn error_msg_inner(_: NonZeroU32) -> Option<&'static str> { None }
19+
pub fn error_msg_inner(_: NonZeroU32) -> Option<&'static str> {
20+
None
21+
}

src/lib.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@
4545
//! features are activated for this crate. Note that if both features are
4646
//! enabled `wasm-bindgen` will be used. If neither feature is enabled,
4747
//! `getrandom` will always fail.
48-
//!
48+
//!
4949
//! The WASI target `wasm32-wasi` uses the `__wasi_random_get` function defined
5050
//! by the WASI standard.
51-
//!
51+
//!
5252
//!
5353
//! ## Early boot
5454
//!
@@ -115,18 +115,22 @@
115115
//! [16]: #support-for-webassembly-and-amsjs
116116
//! [17]: https://github.com/CraneStation/wasmtime/blob/master/docs/WASI-api.md#__wasi_random_get
117117
118-
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
119-
html_favicon_url = "https://www.rust-lang.org/favicon.ico",
120-
html_root_url = "https://rust-random.github.io/rand/")]
118+
#![doc(
119+
html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
120+
html_favicon_url = "https://www.rust-lang.org/favicon.ico",
121+
html_root_url = "https://rust-random.github.io/rand/"
122+
)]
121123
#![no_std]
122-
#![cfg_attr(feature = "stdweb", recursion_limit="128")]
124+
#![cfg_attr(feature = "stdweb", recursion_limit = "128")]
123125

124126
#[cfg(feature = "log")]
125127
#[macro_use]
126128
extern crate log;
127129
#[cfg(not(feature = "log"))]
128130
#[allow(unused)]
129-
macro_rules! error { ($($x:tt)*) => () }
131+
macro_rules! error {
132+
($($x:tt)*) => {};
133+
}
130134

131135
// temp fix for stdweb
132136
#[cfg(target_arch = "wasm32")]
@@ -144,13 +148,14 @@ macro_rules! mod_use {
144148
#[$cond]
145149
mod $module;
146150
#[$cond]
147-
use crate::$module::{getrandom_inner, error_msg_inner};
148-
}
151+
use crate::$module::{error_msg_inner, getrandom_inner};
152+
};
149153
}
150154

151155
#[cfg(any(
152156
feature = "std",
153-
windows, unix,
157+
windows,
158+
unix,
154159
target_os = "cloudabi",
155160
target_os = "redox",
156161
target_arch = "wasm32",
@@ -238,7 +243,6 @@ mod_use!(
238243
dummy
239244
);
240245

241-
242246
/// Fill `dest` with random bytes from the system's preferred random number
243247
/// source.
244248
///

src/linux_android.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ use std::io;
1616

1717
fn syscall_getrandom(dest: &mut [u8], block: bool) -> Result<usize, io::Error> {
1818
let flags = if block { 0 } else { libc::GRND_NONBLOCK };
19-
let ret = unsafe {
20-
libc::syscall(libc::SYS_getrandom, dest.as_mut_ptr(), dest.len(), flags)
21-
};
19+
let ret = unsafe { libc::syscall(libc::SYS_getrandom, dest.as_mut_ptr(), dest.len(), flags) };
2220
if ret < 0 {
2321
let err = io::Error::last_os_error();
2422
if err.raw_os_error() == Some(libc::EINTR) {
@@ -31,15 +29,17 @@ fn syscall_getrandom(dest: &mut [u8], block: bool) -> Result<usize, io::Error> {
3129
}
3230

3331
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
34-
lazy_static! { static ref HAS_GETRANDOM: bool = is_getrandom_available(); }
32+
lazy_static! {
33+
static ref HAS_GETRANDOM: bool = is_getrandom_available();
34+
}
3535
match *HAS_GETRANDOM {
3636
true => {
3737
let mut start = 0;
3838
while start < dest.len() {
3939
start += syscall_getrandom(&mut dest[start..], true)?;
4040
}
4141
Ok(())
42-
},
42+
}
4343
false => use_file::getrandom_inner(dest),
4444
}
4545
}
@@ -48,12 +48,14 @@ fn is_getrandom_available() -> bool {
4848
match syscall_getrandom(&mut [], false) {
4949
Err(err) => match err.raw_os_error() {
5050
Some(libc::ENOSYS) => false, // No kernel support
51-
Some(libc::EPERM) => false, // Blocked by seccomp
51+
Some(libc::EPERM) => false, // Blocked by seccomp
5252
_ => true,
53-
}
53+
},
5454
Ok(_) => true,
5555
}
5656
}
5757

5858
#[inline(always)]
59-
pub fn error_msg_inner(_: NonZeroU32) -> Option<&'static str> { None }
59+
pub fn error_msg_inner(_: NonZeroU32) -> Option<&'static str> {
60+
None
61+
}

0 commit comments

Comments
 (0)