From a2e50c7b5158b21910a64588e6db81bb66a91833 Mon Sep 17 00:00:00 2001 From: Andrea Fioraldi Date: Tue, 27 Oct 2020 15:50:32 +0100 Subject: [PATCH] random as generic parameter in corpus --- src/corpus/mod.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/corpus/mod.rs b/src/corpus/mod.rs index 6ba7c838cc..6bd144b373 100644 --- a/src/corpus/mod.rs +++ b/src/corpus/mod.rs @@ -31,13 +31,13 @@ pub trait Corpus: Debug { } #[derive(Debug)] -pub struct RandomCorpus<'a> { - rand: &'a mut dyn Rand, +pub struct RandomCorpus<'a, RandT: Rand> { + rand: &'a mut RandT, entries: Vec>, dir_path: String, } -impl Corpus for RandomCorpus<'_> { +impl Corpus for RandomCorpus<'_, RandT> { /// Returns the number of elements fn count(&self) -> usize { self.entries.len() @@ -76,8 +76,8 @@ impl Corpus for RandomCorpus<'_> { } } -impl RandomCorpus<'_> { - pub fn new<'a>(rand: &'a mut dyn Rand, dir_path: &str) -> RandomCorpus<'a> { +impl RandomCorpus<'_, RandT> { + pub fn new<'a>(rand: &'a mut RandT, dir_path: &str) -> RandomCorpus<'a, RandT> { RandomCorpus { dir_path: dir_path.to_owned(), entries: vec![], @@ -88,13 +88,13 @@ impl RandomCorpus<'_> { /// A queue-like corpus #[derive(Debug)] -pub struct QueueCorpus<'a> { - random_corpus: RandomCorpus<'a>, +pub struct QueueCorpus<'a, RandT: Rand> { + random_corpus: RandomCorpus<'a, RandT>, pos: usize, cycles: u64, } -impl Corpus for QueueCorpus<'_> { +impl Corpus for QueueCorpus<'_, RandT> { /// Returns the number of elements fn count(&self) -> usize { self.random_corpus.count() @@ -128,8 +128,8 @@ impl Corpus for QueueCorpus<'_> { } } -impl QueueCorpus<'_> { - pub fn new<'a>(rand: &'a mut dyn Rand, dir_path: &str) -> QueueCorpus<'a> { +impl QueueCorpus<'_, RandT> { + pub fn new<'a>(rand: &'a mut RandT, dir_path: &str) -> QueueCorpus<'a, RandT> { QueueCorpus { random_corpus: RandomCorpus::new(rand, dir_path), cycles: 0,