]> git.lizzy.rs Git - generate-random.git/commitdiff
Support Vec
authorLizzy Fleckenstein <eliasfleckenstein@web.de>
Mon, 6 Feb 2023 15:51:30 +0000 (16:51 +0100)
committerLizzy Fleckenstein <eliasfleckenstein@web.de>
Mon, 6 Feb 2023 15:51:30 +0000 (16:51 +0100)
lib/src/lib.rs

index 67432e306d6bd02bda0394214e276fc87299a527..3b555f295ba6b5a8c9cb5d7f0e69ae9e8193f76f 100644 (file)
@@ -108,6 +108,13 @@ impl GenerateRandom for String {
     }
 }
 
+impl<T: GenerateRandom> GenerateRandom for Vec<T> {
+    fn generate_random<R: rand::Rng + ?Sized>(rng: &mut R) -> Self {
+        let len = rng.gen_range(0..8);
+        (0..len).map(|_| T::generate_random(rng)).collect()
+    }
+}
+
 macro_rules! impl_generate_random_tuple {
        ( $t0:ident $( $t:ident )* ) => {
                impl< $t0, $( $t, )* > GenerateRandom for ( $t0, $( $t, )* )