From 57dfb60fdc38d7b4815087d71781e2b326c6939b Mon Sep 17 00:00:00 2001 From: pommicket Date: Thu, 26 Jan 2023 13:38:12 -0500 Subject: more documentation --- gen_random/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gen_random') diff --git a/gen_random/src/lib.rs b/gen_random/src/lib.rs index 4bd67be..b75d8cc 100644 --- a/gen_random/src/lib.rs +++ b/gen_random/src/lib.rs @@ -4,7 +4,10 @@ use std::rc::Rc; use std::sync::Arc; use std::cell::{Cell, RefCell}; +/// parameters passed to [GenRandom] implementation pub trait GenRandomParams: Sized + Default + Copy { + /// If `params` is used to generate `object`, then `params.inc_depth()` will + /// be used to generate `object`'s members. fn inc_depth(self) -> Self; } @@ -14,6 +17,7 @@ impl GenRandomParams for () { } } + impl GenRandomParams for i64 { fn inc_depth(self) -> Self { self - 1 @@ -73,10 +77,12 @@ pub trait GenRandom: Sized { } } +/// generate a [Vec] of `len` random items. pub fn gen_random_vec>(rng: &mut impl Rng, len: usize) -> Vec { (0..len).map(|_| T::gen_random(rng)).collect() } +/// generate a [Vec] of `len` random items using `rand::thread_rng()`. pub fn gen_thread_random_vec>(len: usize) -> Vec { gen_random_vec(&mut rand::thread_rng(), len) } -- cgit v1.2.3