use core::fmt;
#[derive(Clone, Debug)]
pub struct Rng09<T: rand_core_0_9::RngCore>(pub T);
#[derive(Clone, Debug)]
pub struct TryRng09<T: rand_core_0_9::TryRngCore>(pub T);
#[derive(Debug)]
pub struct Error09<T: fmt::Debug + fmt::Display + Send + Sync + 'static>(pub T);
#[cfg(feature = "std")]
impl<T: fmt::Debug + fmt::Display + Send + Sync + 'static> std::error::Error for Error09<T> {}
impl<T: fmt::Debug + fmt::Display + Send + Sync + 'static> fmt::Display for Error09<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.0, f)
}
}
#[cfg(feature = "rand_core_0_5")]
mod v0_5 {
use super::Error09;
use super::Rng09;
use super::TryRng09;
use core::fmt;
impl<T: rand_core_0_9::RngCore> rand_core_0_5::RngCore for Rng09<T> {
fn next_u32(&mut self) -> u32 {
self.0.next_u32()
}
fn next_u64(&mut self) -> u64 {
self.0.next_u64()
}
fn fill_bytes(&mut self, dst: &mut [u8]) {
self.0.fill_bytes(dst)
}
fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), rand_core_0_5::Error> {
self.0.fill_bytes(dst);
Ok(())
}
}
impl<T: rand_core_0_9::CryptoRng> rand_core_0_5::CryptoRng for Rng09<T> {}
impl<T: rand_core_0_9::TryRngCore> rand_core_0_5::RngCore for TryRng09<T>
where
T::Error: Send + Sync + 'static,
{
fn next_u32(&mut self) -> u32 {
rand_core_0_5::impls::next_u32_via_fill(self)
}
fn next_u64(&mut self) -> u64 {
rand_core_0_5::impls::next_u64_via_fill(self)
}
fn fill_bytes(&mut self, dst: &mut [u8]) {
self.0.try_fill_bytes(dst).unwrap();
}
fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), rand_core_0_5::Error> {
Ok(self.0.try_fill_bytes(dst).map_err(Error09)?)
}
}
impl<T: rand_core_0_9::TryCryptoRng> rand_core_0_5::CryptoRng for TryRng09<T> {}
impl<T: fmt::Debug + fmt::Display + Send + Sync + 'static> From<Error09<T>>
for rand_core_0_5::Error
{
fn from(error: Error09<T>) -> rand_core_0_5::Error {
#[cfg(feature = "std")]
{
rand_core_0_5::Error::new(error)
}
#[cfg(not(feature = "std"))]
{
use crate::error;
let _ = error;
error::UNKNOWN.into()
}
}
}
}
#[cfg(feature = "rand_core_0_6")]
mod v0_6 {
use super::Error09;
use super::Rng09;
use super::TryRng09;
use core::fmt;
impl<T: rand_core_0_9::RngCore> rand_core_0_6::RngCore for Rng09<T> {
fn next_u32(&mut self) -> u32 {
self.0.next_u32()
}
fn next_u64(&mut self) -> u64 {
self.0.next_u64()
}
fn fill_bytes(&mut self, dst: &mut [u8]) {
self.0.fill_bytes(dst)
}
fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), rand_core_0_6::Error> {
self.0.fill_bytes(dst);
Ok(())
}
}
impl<T: rand_core_0_9::CryptoRng> rand_core_0_6::CryptoRng for Rng09<T> {}
impl<T: rand_core_0_9::TryRngCore> rand_core_0_6::RngCore for TryRng09<T>
where
T::Error: Send + Sync + 'static,
{
fn next_u32(&mut self) -> u32 {
rand_core_0_6::impls::next_u32_via_fill(self)
}
fn next_u64(&mut self) -> u64 {
rand_core_0_6::impls::next_u64_via_fill(self)
}
fn fill_bytes(&mut self, dst: &mut [u8]) {
self.0.try_fill_bytes(dst).unwrap();
}
fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), rand_core_0_6::Error> {
Ok(self.0.try_fill_bytes(dst).map_err(Error09)?)
}
}
impl<T: rand_core_0_9::TryCryptoRng> rand_core_0_6::CryptoRng for TryRng09<T> {}
impl<T: fmt::Debug + fmt::Display + Send + Sync + 'static> From<Error09<T>>
for rand_core_0_6::Error
{
fn from(error: Error09<T>) -> rand_core_0_6::Error {
#[cfg(feature = "std")]
{
rand_core_0_6::Error::new(error)
}
#[cfg(not(feature = "std"))]
{
use crate::error;
let _ = error;
error::UNKNOWN.into()
}
}
}
}
#[cfg(feature = "rand_core_0_10")]
mod v0_10 {
use super::Rng09;
use super::TryRng09;
use core::convert::Infallible;
use core::error::Error;
impl<T: rand_core_0_9::RngCore> rand_core_0_10::TryRng for Rng09<T> {
type Error = Infallible;
fn try_next_u32(&mut self) -> Result<u32, Infallible> {
Ok(self.0.next_u32())
}
fn try_next_u64(&mut self) -> Result<u64, Infallible> {
Ok(self.0.next_u64())
}
fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), Infallible> {
Ok(self.0.fill_bytes(dst))
}
}
impl<T: rand_core_0_9::RngCore + rand_core_0_9::CryptoRng> rand_core_0_10::TryCryptoRng
for Rng09<T>
{
}
impl<T: rand_core_0_9::TryRngCore> rand_core_0_10::TryRng for TryRng09<T>
where
T::Error: Error,
{
type Error = T::Error;
fn try_next_u32(&mut self) -> Result<u32, T::Error> {
self.0.try_next_u32()
}
fn try_next_u64(&mut self) -> Result<u64, T::Error> {
self.0.try_next_u64()
}
fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), T::Error> {
self.0.try_fill_bytes(dst)
}
}
impl<T: rand_core_0_9::TryRngCore + rand_core_0_9::TryCryptoRng> rand_core_0_10::TryCryptoRng
for TryRng09<T>
where
T::Error: Error,
{
}
}