helper.rs - source
Description: Source of the Rust file `/Users/erlendbasso/.cargo/registry/src/github.com-1ecc6299db9ec823/nalgebra-0.32.1/src/base/helper.rs`.
Keywords: rust, rustlang, rust-lang

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31

    #[cfg(feature = "arbitrary")]
    use quickcheck::{Arbitrary, Gen};

    #[cfg(feature = "rand-no-std")]
    use rand::{
        distributions::{Distribution, Standard},
        Rng,
    };

    /// Simple helper function for rejection sampling
    #[cfg(feature = "arbitrary")]
    #[doc(hidden)]
    #[inline]
    pub fn reject<F: FnMut(&T) -> bool, T: Arbitrary>(g: &mut Gen, f: F) -> T {
        use std::iter;
        iter::repeat(())
            .map(|_| Arbitrary::arbitrary(g))
            .find(f)
            .unwrap()
    }

    #[doc(hidden)]
    #[inline]
    #[cfg(feature = "rand-no-std")]
    pub fn reject_rand<G: Rng + ?Sized, F: FnMut(&T) -> bool, T>(g: &mut G, f: F) -> T
    where
        Standard: Distribution<T>,
    {
        use std::iter;
        iter::repeat(()).map(|_| g.gen()).find(f).unwrap()
    }