cryprot_core/
rand_compat.rs

1//! Compatability wrapper between rand_core 0.9 and rand_core 0.6.
2use rand::{CryptoRng, RngCore};
3
4/// Compatability wrapper between rand_core 0.9 and rand_core 0.6.
5///
6/// This implements the [`rand_core_0_6::RngCore`] and
7/// [`rand_core_0_6::CryptoRng`] for any version 0.9 RNG that implements the
8/// corresponding traits.
9pub struct RngCompat<R>(pub R);
10
11impl<R: RngCore> rand_core_0_6::RngCore for RngCompat<R> {
12    #[inline]
13    fn next_u32(&mut self) -> u32 {
14        self.0.next_u32()
15    }
16
17    #[inline]
18    fn next_u64(&mut self) -> u64 {
19        self.0.next_u64()
20    }
21
22    #[inline]
23    fn fill_bytes(&mut self, dest: &mut [u8]) {
24        self.0.fill_bytes(dest);
25    }
26
27    #[inline]
28    fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core_0_6::Error> {
29        self.0.fill_bytes(dest);
30        Ok(())
31    }
32}
33
34impl<R: CryptoRng> rand_core_0_6::CryptoRng for RngCompat<R> {}