nalgebra/base/
helper.rs
1#[cfg(feature = "arbitrary")]
2use quickcheck::{Arbitrary, Gen};
3
4#[cfg(feature = "rand-no-std")]
5use rand::{
6 distributions::{Distribution, Standard},
7 Rng,
8};
9
10#[cfg(feature = "arbitrary")]
12#[doc(hidden)]
13#[inline]
14pub fn reject<F: FnMut(&T) -> bool, T: Arbitrary>(g: &mut Gen, f: F) -> T {
15 use std::iter;
16 iter::repeat(())
17 .map(|_| Arbitrary::arbitrary(g))
18 .find(f)
19 .unwrap()
20}
21
22#[doc(hidden)]
23#[inline]
24#[cfg(feature = "rand-no-std")]
25pub fn reject_rand<G: Rng + ?Sized, F: FnMut(&T) -> bool, T>(g: &mut G, f: F) -> T
26where
27 Standard: Distribution<T>,
28{
29 use std::iter;
30 iter::repeat(()).map(|_| g.gen()).find(f).unwrap()
31}