// Copyright 2018 Developers of the Rand project. // Copyright 2013 The Rust Project Developers. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // https://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms.
//! A wrapper around any Read to treat it as an RNG.
#![allow(deprecated)]
use std::fmt; use std::io::Read;
use rand_core::{impls, Error, RngCore};
/// An RNG that reads random bytes straight from any type supporting /// [`std::io::Read`], for example files. /// /// This will work best with an infinite reader, but that is not required. /// /// This can be used with `/dev/urandom` on Unix but it is recommended to use /// [`OsRng`] instead. /// /// # Panics /// /// `ReadRng` uses [`std::io::Read::read_exact`], which retries on interrupts. /// All other errors from the underlying reader, including when it does not /// have enough data, will only be reported through [`try_fill_bytes`]. /// The other [`RngCore`] methods will panic in case of an error. /// /// [`OsRng`]: crate::rngs::OsRng /// [`try_fill_bytes`]: RngCore::try_fill_bytes #[derive(Debug)] #[deprecated(since="0.8.4", note="removal due to lack of usage")] pubstruct ReadRng<R> {
reader: R,
}
impl<R: Read> ReadRng<R> { /// Create a new `ReadRng` from a `Read`. pubfn new(r: R) -> ReadRng<R> {
ReadRng { reader: r }
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.