Skip to content

Commit

Permalink
update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stevefan1999-personal committed Sep 25, 2024
1 parent 6ed88f0 commit 3205704
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn get_rng_danger() -> &'static mut (dyn RngCore + Send + Sync) {
}

// SAFETY: If randomness source is not already set, the whole program panics due to the unwrap
// UNSAFETY: If you have a memory corruption (whether stack or heap or not), this could
// UNSAFETY: If you have a memory corruption (whether stack or heap or not), this assumption could be violated
#[allow(static_mut_refs)]
unsafe {
RNG.get_mut().expect("RNG was not set").as_mut()
Expand All @@ -98,7 +98,7 @@ fn get_rng_danger() -> &'static mut (dyn RngCore + Send + Sync) {

// Initialize an RNG source, and panic if it was already set, which would only happen if two threads set the data at the same time.
// This ensures the user would have to decide on the RNG source at the very beginning, likely the first function call in main and find way to provide entropy themselves
// TIP: Use Box::from_raw to prevent having to do real heap allocation if you can assume your program to be single-threaded and your put RNG state as a global variable
// TIP: Use Box::from_raw to prevent having to do real heap allocation if you can assume your program to be single-threaded and you put RNG state as a global variable, which is usually useful for MCUs
#[cfg(feature = "alloc")]
pub fn init_randomness_source(rng: Box<dyn RngCore + Send + Sync>) {
// SAFETY: If randomness source is already set, the whole program panics
Expand Down

0 comments on commit 3205704

Please sign in to comment.