Skip to content

Commit 60f6cc7

Browse files
committed
Run Rustfmt
1 parent 6aed788 commit 60f6cc7

7 files changed

Lines changed: 40 additions & 39 deletions

File tree

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/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/lib.rs

Lines changed: 17 additions & 16 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,23 +115,28 @@
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")]
133137
extern crate std;
134138

139+
mod error;
135140
#[cfg(any(
136141
target_os = "android",
137142
target_os = "netbsd",
@@ -141,13 +146,9 @@ extern crate std;
141146
target_os = "dragonfly",
142147
target_os = "haiku",
143148
target_os = "linux",
144-
all(
145-
target_arch = "wasm32",
146-
not(target_os = "wasi")
147-
),
149+
all(target_arch = "wasm32", not(target_os = "wasi")),
148150
))]
149151
mod utils;
150-
mod error;
151152
pub use crate::error::Error;
152153

153154
// System-specific implementations.
@@ -159,13 +160,14 @@ macro_rules! mod_use {
159160
#[$cond]
160161
mod $module;
161162
#[$cond]
162-
use crate::$module::{getrandom_inner, error_msg_inner};
163-
}
163+
use crate::$module::{error_msg_inner, getrandom_inner};
164+
};
164165
}
165166

166167
#[cfg(any(
167168
feature = "std",
168-
windows, unix,
169+
windows,
170+
unix,
169171
target_os = "cloudabi",
170172
target_os = "redox",
171173
target_arch = "wasm32",
@@ -246,7 +248,6 @@ mod_use!(
246248
dummy
247249
);
248250

249-
250251
/// Fill `dest` with random bytes from the system's preferred random number
251252
/// source.
252253
///

src/utils.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ use core::ops::DerefMut;
1212
/// If `f` contains `Some(T)` call `use_f` using contents of `f` as an argument,
1313
/// otherwise initialize `f` value using `init_f`, store resulting value in `f`
1414
/// and call `use_f`.
15-
pub(crate) fn use_init<T, F, U>(f: &RefCell<Option<T>>, init_f: F, mut use_f: U)
16-
-> Result<(), Error>
17-
where F: FnOnce() -> Result<T, Error>, U: FnMut(&mut T) -> Result<(), Error>
15+
pub(crate) fn use_init<T, F, U>(
16+
f: &RefCell<Option<T>>,
17+
init_f: F,
18+
mut use_f: U,
19+
) -> Result<(), Error>
20+
where
21+
F: FnOnce() -> Result<T, Error>,
22+
U: FnMut(&mut T) -> Result<(), Error>,
1823
{
1924
let mut f = f.borrow_mut();
2025
let f: &mut Option<T> = f.deref_mut();

tests/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ fn test_huge() {
3131
getrandom(&mut huge).unwrap();
3232
}
3333

34-
#[cfg(any(unix, windows, target_os="redox", target_os = "fuchsia"))]
34+
#[cfg(any(unix, windows, target_os = "redox", target_os = "fuchsia"))]
3535
#[test]
3636
fn test_multithreading() {
3737
use std::sync::mpsc::channel;
3838
use std::thread;
3939

40-
let mut txs = vec!();
40+
let mut txs = vec![];
4141
for _ in 0..20 {
4242
let (tx, rx) = channel();
4343
txs.push(tx);
4444

45-
thread::spawn(move|| {
45+
thread::spawn(move || {
4646
// wait until all the tasks are ready to go.
4747
rx.recv().unwrap();
4848
let mut v = [0u8; 1000];

tests/wasm_bindgen/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ extern crate wasm_bindgen;
1515
extern crate wasm_bindgen_test;
1616

1717
use std::slice;
18-
use wasm_bindgen_test::*;
1918
use wasm_bindgen::prelude::*;
19+
use wasm_bindgen_test::*;
2020

2121
use getrandom::getrandom;
2222

0 commit comments

Comments
 (0)