Skip to content

Commit

Permalink
refactor(random): rewrite a static assert checking for an impl
Browse files Browse the repository at this point in the history
This verifies that `SelectedRng` is indeed a CSRNG using a shorter,
arguably easier to read construct. It is also easier to make clippy
happy about it.
  • Loading branch information
ROMemories authored and chrysn committed Apr 15, 2024
1 parent 48060e8 commit e343fd3
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/riot-rs-random/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,8 @@ mod csprng {
impl rand_core::CryptoRng for super::CryptoRng {}

/// Asserts that SelectedRng is CryptoRng, justifying the implementation above.
fn static_assert_is_cryptorng() -> impl rand_core::CryptoRng {
let result: super::SelectedRng = unreachable!("This function is for type checking only");
result
}
trait _AssertCryptoRng: rand_core::CryptoRng {}
impl _AssertCryptoRng for SelectedRng {}
}

/// Populates the global RNG from a seed value.
Expand Down

0 comments on commit e343fd3

Please sign in to comment.