Skip to content

Commit

Permalink
random: Make Rng not Send
Browse files Browse the repository at this point in the history
If the type were Send, some thread-local backends may be excluded, and
Send is a trait that can not later be removed without breaking.
  • Loading branch information
chrysn authored and kaspar030 committed Apr 12, 2024
1 parent ff58994 commit 4eb2a70
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/riot-rs-random/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ pub(crate) type SelectedRng = rand_chacha::ChaCha20Rng;
/// depend on a known fast RNG and seed it from the OS's RNG, but preferably there should be a
/// single configured implementation used across applications for ROM optimization, even if it
/// turns out to be beneficial to have a thread or task local RNG around in RAM for speed).
pub struct Rng;
pub struct Rng {
// Make the type not Send
_private: core::marker::PhantomData<*const ()>,
}

impl Rng {
fn with<R>(&mut self, action: impl FnOnce(&mut SelectedRng) -> R) -> R {
Expand Down Expand Up @@ -112,5 +115,7 @@ pub fn construct_rng(hwrng: impl RngCore) {
/// macros.
#[inline]
pub fn get_rng() -> Rng {
Rng
Rng {
_private: Default::default(),
}
}

0 comments on commit 4eb2a70

Please sign in to comment.