Struct prop_check_rs::rng::RNG

source ·
pub struct RNG { /* private fields */ }

Implementations§

Examples found in repository?
src/rng.rs (line 102)
101
102
103
  fn default() -> Self {
    Self::new()
  }
Examples found in repository?
src/rng.rs (line 194)
193
194
195
196
  pub fn f32_i32(&self) -> ((f32, i32), Self) {
    let ((i, d), r) = self.i32_f32();
    ((d, i), r)
  }
Examples found in repository?
src/rng.rs (line 228)
224
225
226
227
228
229
230
231
232
233
234
235
236
  pub fn sequence<A, F>(fs: Vec<F>) -> BoxRand<Vec<A>>
  where
    A: Clone + 'static,
    F: FnMut(RNG) -> (A, RNG) + 'static, {
    let unit = Self::unit(Vec::<A>::new());
    let result = fs.into_iter().fold(unit, |acc, e| {
      Self::map2(acc, e, |mut a, b| {
        a.push(b);
        a
      })
    });
    result
  }
Examples found in repository?
src/rng.rs (line 276)
275
276
277
278
279
280
281
  pub fn rand_int_double() -> BoxRand<(i32, f32)> {
    Self::both(Self::int_value(), Self::double_value())
  }

  pub fn rand_double_int<'a>() -> BoxRand<(f32, i32)> {
    Self::both(Self::double_value(), Self::int_value())
  }
Examples found in repository?
src/rng.rs (line 276)
275
276
277
278
279
280
281
  pub fn rand_int_double() -> BoxRand<(i32, f32)> {
    Self::both(Self::int_value(), Self::double_value())
  }

  pub fn rand_double_int<'a>() -> BoxRand<(f32, i32)> {
    Self::both(Self::double_value(), Self::int_value())
  }
Examples found in repository?
src/rng.rs (lines 230-233)
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
  pub fn sequence<A, F>(fs: Vec<F>) -> BoxRand<Vec<A>>
  where
    A: Clone + 'static,
    F: FnMut(RNG) -> (A, RNG) + 'static, {
    let unit = Self::unit(Vec::<A>::new());
    let result = fs.into_iter().fold(unit, |acc, e| {
      Self::map2(acc, e, |mut a, b| {
        a.push(b);
        a
      })
    });
    result
  }

  pub fn int_value() -> BoxRand<i32> {
    Box::new(move |rng| rng.next_i32())
  }

  pub fn double_value() -> BoxRand<f32> {
    Box::new(move |rng| rng.next_f32())
  }

  pub fn map<A, B, F1, F2>(mut s: F1, mut f: F2) -> BoxRand<B>
  where
    F1: FnMut(RNG) -> (A, RNG) + 'static,
    F2: FnMut(A) -> B + 'static, {
    Box::new(move |rng| {
      let (a, rng2) = s(rng);
      (f(a), rng2)
    })
  }

  pub fn map2<F1, F2, F3, A, B, C>(mut ra: F1, mut rb: F2, mut f: F3) -> BoxRand<C>
  where
    F1: FnMut(RNG) -> (A, RNG) + 'static,
    F2: FnMut(RNG) -> (B, RNG) + 'static,
    F3: FnMut(A, B) -> C + 'static, {
    Box::new(move |rng| {
      let (a, r1) = ra(rng);
      let (b, r2) = rb(r1);
      (f(a, b), r2)
    })
  }

  pub fn both<F1, F2, A, B>(ra: F1, rb: F2) -> BoxRand<(A, B)>
  where
    F1: FnMut(RNG) -> (A, RNG) + 'static,
    F2: FnMut(RNG) -> (B, RNG) + 'static, {
    Self::map2(ra, rb, |a, b| (a, b))
  }
Examples found in repository?
src/rng.rs (line 276)
275
276
277
278
279
280
281
  pub fn rand_int_double() -> BoxRand<(i32, f32)> {
    Self::both(Self::int_value(), Self::double_value())
  }

  pub fn rand_double_int<'a>() -> BoxRand<(f32, i32)> {
    Self::both(Self::double_value(), Self::int_value())
  }

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.