Skip to content

Bumping MSRV of getrandom 0.2 #286

Closed
@josephlr

Description

@josephlr

A few issues and PRs (#279 #281) have brought up the idea of increasing the MSRV of this crate. Currently the MSRV is 1.34, and I've seen 3 features we might want to use which are only present in later versions:

  • MaybeUninit: added in 1.36 (Released 2019-07-04)
  • <*mut T>::cast: added in 1.38 (Released 2019-09-26)
  • Const Generics: Added in 1.51 (Released 2021-03-25)

When raising the MSRV, we should keep in mind that rand 0.8 and rand_core 0.6 have an MSRV of 1.36, and they are our largest users. Other top crates that directly depend on us include:

Also, we can always use rustversion to have APIs that require a newer version of Rust without increasing our MSRV, provided we can implement the newer API in terms of one of the older APIs.

I would propose: raising the MSRV to 1.36 so we can use MaybeUninit inside of our crate.

For example,

pub fn getrandom_uninit(buf: &mut [MaybeUninit<u8>]) -> Result<&[u8], Error> {
  // Unconditionally use MaybeUninit
  // ...
}

#[rustversion::since(1.51)]
#[inline]
pub fn getrandom_array<const N: usize>() -> Result<[u8; N], Error> {
  let mut arr: [MaybeUninit<u8>; N] = [MaybeUninit;;uninit(); N];
  let s: &mut [u8; N] = getrandom_uninit(&mut arr)?.try_into().unwrap();
  Ok(*s)
}

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions