Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion rapidrand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#![deny(unused_must_use)]

#[cfg(feature = "rand")]
use rand_core::{SeedableRng, TryRng, utils::fill_bytes_via_next_word};
use rand_core::{Rng, SeedableRng, TryRng, utils::fill_bytes_via_next_word};

/// Rapidhash V1 secret[0].
///
Expand Down Expand Up @@ -171,4 +171,17 @@ impl SeedableRng for RapidRng {
state: rapidrng(&mut state),
}
}

fn from_rng<R: Rng + ?Sized>(rng: &mut R) -> Self {
Self {
state: rng.next_u64(),
}
}

fn try_from_rng<R: TryRng + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
match rng.try_next_u64() {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just unsugared ?, mostly done this way to optimise dev compile times to keep them fast. For release mode, it all gets optimised pretty well anyway and makes small difference to compile speed. Runtime speed should be the same.

Ok(state) => Ok(Self { state }),
Err(e) => Err(e),
}
}
}