remove unsafe and newlines, add notice

This commit is contained in:
newpavlov 2019-02-06 13:04:47 +03:00
parent 9855b52df2
commit 5ebbaf787e
9 changed files with 12 additions and 11 deletions

View File

@ -20,4 +20,3 @@ pub fn getrandom(dest: &mut [u8]) -> Result<(), Error> {
use_init(f, || File::open("/dev/random"), |f| f.read_exact(dest))
}).map_err(|_| Error::Unknown)
}

View File

@ -29,4 +29,3 @@ pub fn getrandom(dest: &mut [u8]) -> Result<(), Error> {
})
}).map_err(|_| Error::Unknown)
}

View File

@ -29,4 +29,3 @@ pub fn getrandom(dest: &mut [u8]) -> Result<(), Error> {
}
Ok(())
}

View File

@ -15,4 +15,3 @@ pub fn getrandom(dest: &mut [u8]) -> Result<(), Error> {
fuchsia_cprng::cprng_draw(dest);
Ok(())
}

View File

@ -111,4 +111,3 @@ mod_use!(
))),
dummy
);

View File

@ -26,4 +26,3 @@ pub fn getrandom(dest: &mut [u8]) -> Result<(), Error> {
}, |f| f.read_exact(dest))
}).map_err(|_| Error::Unknown)
}

View File

@ -25,4 +25,3 @@ pub fn getrandom(dest: &mut [u8]) -> Result<(), Error> {
}
Ok(())
}

View File

@ -20,4 +20,3 @@ pub fn getrandom(dest: &mut [u8]) -> Result<(), Error> {
use_init(f, || File::open("rand:"), |f| f.read_exact(dest))
}).map_err(|_| Error::Unknown)
}

View File

@ -1,7 +1,17 @@
// Copyright 2018 Developers of the Rand project.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::cell::RefCell;
use std::ops::DerefMut;
use std::{io, hint};
use std::io;
/// If `f` contains `Some(T)` call `use_f` using contents of `f` as an argument,
/// otherwise initialize `f` value using `init_f`, store resulting value in `f`
/// and call `use_f`.
pub(crate) fn use_init<T, F, U>(f: &RefCell<Option<T>>, init_f: F, mut use_f: U)
-> io::Result<()>
where F: FnOnce() -> io::Result<T>, U: FnMut(&mut T) -> io::Result<()>
@ -15,7 +25,6 @@ pub(crate) fn use_init<T, F, U>(f: &RefCell<Option<T>>, init_f: F, mut use_f: U)
match f {
Some(f) => use_f(f),
None => unsafe { hint::unreachable_unchecked() },
None => unreachable!(),
}
}