From 01abd13b544c567c08f43b4e51a028014ce8ada5 Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Sun, 23 May 2021 11:50:34 +1000 Subject: [PATCH] Add `Gen::fill` method This allows users to fairly easily migrate from CoreRng::fill_byte() and similar constructions without requiring them to fuss around with a new SeedableRng (or copy-paste this boilerplate) when their slice is just full of Arbitrary-able types. Signed-off-by: Aleksa Sarai --- src/arbitrary.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/arbitrary.rs b/src/arbitrary.rs index b1e29de..abb1144 100644 --- a/src/arbitrary.rs +++ b/src/arbitrary.rs @@ -64,6 +64,16 @@ impl Gen { slice.choose(&mut self.rng) } + /// Fill a mutable slice of any Arbitrary-compatible type with Arbitrary + /// values. + pub fn fill(&mut self, mut slice: S) + where + T: Arbitrary, + S: AsMut<[T]>, + { + slice.as_mut().fill_with(|| T::arbitrary(self)) + } + fn gen(&mut self) -> T where rand::distributions::Standard: rand::distributions::Distribution,