#![deny(clippy::all)]
#![deny(clippy::pedantic)]
#![deny(clippy::cargo)]
#![allow(unknown_lints)]
#![deny(missing_debug_implementations)]
#![warn(missing_docs)]
#![warn(rust_2018_idioms)]
#![warn(trivial_casts, trivial_numeric_casts)]
#![warn(unused_qualifications)]
#![warn(variant_size_differences)]
#![forbid(unsafe_code)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_alias))]
#![cfg_attr(
not(feature = "std"),
doc = "[`std::error::Error`]: https://doc.rust-lang.org/std/error/trait.Error.html"
)]
#![cfg_attr(feature = "std", doc = "[`Box`]: std::boxed::Box")]
#![cfg_attr(
not(feature = "std"),
doc = "[`Box`]: https://doc.rust-lang.org/std/boxed/struct.Box.html"
)]
#![cfg_attr(
not(feature = "rand_core"),
doc = "[`rand_core`]: https://crates.io/crates/rand_core"
)]
#![doc(html_root_url = "https://docs.rs/rand_mt/4.2.2")]
#![no_std]
#[cfg(feature = "std")]
extern crate std;
use core::fmt;
pub use crate::mt::Mt19937GenRand32;
pub use crate::mt64::Mt19937GenRand64;
mod mt;
mod mt64;
#[cfg(test)]
mod vectors;
pub type Mt = Mt19937GenRand32;
pub type Mt64 = Mt19937GenRand64;
#[non_exhaustive]
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum RecoverRngError {
TooFewSamples(usize),
TooManySamples(usize),
}
impl fmt::Display for RecoverRngError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::TooFewSamples(expected) => {
write!(f, "Too few samples given to recover: expected {}", expected)
}
Self::TooManySamples(expected) => write!(
f,
"Too many samples given to recover: expected {}",
expected
),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for RecoverRngError {}
#[cfg(test)]
mod tests {
#[cfg(feature = "std")]
use super::RecoverRngError;
#[test]
#[cfg(feature = "std")]
fn error_display_is_not_empty() {
use core::fmt::Write as _;
use std::string::String;
let test_cases = [
RecoverRngError::TooFewSamples(0),
RecoverRngError::TooFewSamples(124),
RecoverRngError::TooManySamples(0),
RecoverRngError::TooManySamples(987),
];
for tc in test_cases {
let mut buf = String::new();
write!(&mut buf, "{}", tc).unwrap();
assert!(!buf.is_empty());
}
}
}
#[cfg(doctest)]
macro_rules! readme {
($x:expr) => {
#[doc = $x]
mod readme {}
};
() => {
readme!(include_str!("../README.md"));
};
}
#[cfg(doctest)]
readme!();