Skip to content

Commit 350df46

Browse files
authored
Rename getrandom(_uninit) to fill(_uninit) (#532)
The new names are shorter and easier to understand (i.e. compare `getrandom::fill` vs `getrandom::getrandom`).
1 parent 573f855 commit 350df46

27 files changed

+80
-67
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88

99
### Breaking Changes
10-
- Update MSRV to 1.60 [#472]
10+
11+
#### Changed
12+
- Bump MSRV to 1.60 [#472]
13+
- Rename `getrandom` and `getrandom_uninit` functions to `fill` and `fill_uninit` respectively [#532]
1114

1215
#### Removed
1316
- `wasm32-wasi` target support (use `wasm32-wasip1` or `wasm32-wasip2` instead) [#499]
@@ -46,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4649
[#520]: https://github.com/rust-random/getrandom/pull/520
4750
[#521]: https://github.com/rust-random/getrandom/pull/521
4851
[#522]: https://github.com/rust-random/getrandom/pull/522
52+
[#532]: https://github.com/rust-random/getrandom/pull/532
4953

5054
## [0.2.15] - 2024-05-06
5155
### Added

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Then invoke the `getrandom` function:
4040
```rust
4141
fn get_random_buf() -> Result<[u8; 32], getrandom::Error> {
4242
let mut buf = [0u8; 32];
43-
getrandom::getrandom(&mut buf)?;
43+
getrandom::fill(&mut buf)?;
4444
Ok(buf)
4545
}
4646
```

benches/buffer.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ use std::mem::MaybeUninit;
55

66
// Call getrandom on a zero-initialized stack buffer
77
#[inline(always)]
8-
fn bench_getrandom<const N: usize>() {
8+
fn bench_fill<const N: usize>() {
99
let mut buf = [0u8; N];
10-
getrandom::getrandom(&mut buf).unwrap();
10+
getrandom::fill(&mut buf).unwrap();
1111
test::black_box(&buf[..]);
1212
}
1313

14-
// Call getrandom_uninit on an uninitialized stack buffer
14+
// Call fill_uninit on an uninitialized stack buffer
1515
#[inline(always)]
16-
fn bench_getrandom_uninit<const N: usize>() {
16+
fn bench_fill_uninit<const N: usize>() {
1717
let mut uninit = [MaybeUninit::uninit(); N];
18-
let buf: &[u8] = getrandom::getrandom_uninit(&mut uninit).unwrap();
18+
let buf: &[u8] = getrandom::fill_uninit(&mut uninit).unwrap();
1919
test::black_box(buf);
2020
}
2121

@@ -30,20 +30,20 @@ macro_rules! bench {
3030
( $name:ident, $size:expr ) => {
3131
pub mod $name {
3232
#[bench]
33-
pub fn bench_getrandom(b: &mut test::Bencher) {
33+
pub fn bench_fill(b: &mut test::Bencher) {
3434
#[inline(never)]
3535
fn inner() {
36-
super::bench_getrandom::<{ $size }>()
36+
super::bench_fill::<{ $size }>()
3737
}
3838

3939
b.bytes = $size as u64;
4040
b.iter(inner);
4141
}
4242
#[bench]
43-
pub fn bench_getrandom_uninit(b: &mut test::Bencher) {
43+
pub fn bench_fill_uninit(b: &mut test::Bencher) {
4444
#[inline(never)]
4545
fn inner() {
46-
super::bench_getrandom_uninit::<{ $size }>()
46+
super::bench_fill_uninit::<{ $size }>()
4747
}
4848

4949
b.bytes = $size as u64;

nopanic_check/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
1313
#[no_mangle]
1414
pub extern "C" fn getrandom_wrapper(buf_ptr: *mut u8, buf_len: usize) -> u32 {
1515
let buf = unsafe { core::slice::from_raw_parts_mut(buf_ptr.cast(), buf_len) };
16-
let res = getrandom::getrandom_uninit(buf).map(|_| ());
16+
let res = getrandom::fill_uninit(buf).map(|_| ());
1717
unsafe { core::mem::transmute(res) }
1818
}
1919

src/apple-other.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use crate::Error;
33
use core::{ffi::c_void, mem::MaybeUninit};
44

5-
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
5+
pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
66
let dst_ptr = dest.as_mut_ptr().cast::<c_void>();
77
let ret = unsafe { libc::CCRandomGenerateBytes(dst_ptr, dest.len()) };
88
if ret == libc::kCCSuccess {

src/custom.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use crate::Error;
33
use core::mem::MaybeUninit;
44

5-
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
5+
pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
66
extern "Rust" {
77
fn __getrandom_v03_custom(dest: *mut u8, len: usize) -> Result<(), Error>;
88
}

src/esp_idf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extern "C" {
99
fn esp_fill_random(buf: *mut c_void, len: usize) -> u32;
1010
}
1111

12-
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
12+
pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
1313
// Not that NOT enabling WiFi, BT, or the voltage noise entropy source (via `bootloader_random_enable`)
1414
// will cause ESP-IDF to return pseudo-random numbers based on the voltage noise entropy, after the initial boot process:
1515
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/random.html

src/fuchsia.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extern "C" {
77
fn zx_cprng_draw(buffer: *mut u8, length: usize);
88
}
99

10-
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
10+
pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
1111
unsafe { zx_cprng_draw(dest.as_mut_ptr().cast::<u8>(), dest.len()) }
1212
Ok(())
1313
}

src/getentropy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use crate::{util_libc::last_os_error, Error};
1111
use core::{ffi::c_void, mem::MaybeUninit};
1212

13-
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
13+
pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
1414
for chunk in dest.chunks_mut(256) {
1515
let ret = unsafe { libc::getentropy(chunk.as_mut_ptr().cast::<c_void>(), chunk.len()) };
1616
if ret != 0 {

src/getrandom.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use crate::{util_libc::sys_fill_exact, Error};
1919
use core::{ffi::c_void, mem::MaybeUninit};
2020

21-
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
21+
pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
2222
sys_fill_exact(dest, |buf| unsafe {
2323
libc::getrandom(buf.as_mut_ptr().cast::<c_void>(), buf.len(), 0)
2424
})

0 commit comments

Comments
 (0)