tuple for each
This commit is contained in:
parent
1575a3994b
commit
a60ef073ed
@ -181,6 +181,82 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! tuple_for_each {
|
||||||
|
($fn_name:ident, $trait_name:path, $tuple_name:ident, $body:expr) => {
|
||||||
|
mod $fn_name {
|
||||||
|
pub trait ForEach {
|
||||||
|
fn for_each(&self);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ForEach for () {
|
||||||
|
fn for_each(&self) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Head, Tail> ForEach for (Head, Tail)
|
||||||
|
where
|
||||||
|
Head: $trait_name,
|
||||||
|
Tail: tuple_list::TupleList + ForEach,
|
||||||
|
{
|
||||||
|
fn for_each(&self) {
|
||||||
|
($body)(&self.0);
|
||||||
|
self.1.for_each();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
use $fn_name::*;
|
||||||
|
|
||||||
|
$tuple_name.for_each();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! tuple_for_each_mut {
|
||||||
|
($fn_name:ident, $trait_name:path, $tuple_name:ident, $body:expr) => {
|
||||||
|
mod $fn_name {
|
||||||
|
pub trait ForEachMut {
|
||||||
|
fn for_each_mut(&mut self);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ForEachMut for () {
|
||||||
|
fn for_each_mut(&mut self) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Head, Tail> ForEachMut for (Head, Tail)
|
||||||
|
where
|
||||||
|
Head: $trait_name,
|
||||||
|
Tail: tuple_list::TupleList + ForEachMut,
|
||||||
|
{
|
||||||
|
fn for_each_mut(&mut self) {
|
||||||
|
($body)(&mut self.0);
|
||||||
|
self.1.for_each_mut();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
use $fn_name::*;
|
||||||
|
|
||||||
|
$tuple_name.for_each_mut();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
pub fn test_macros() {
|
||||||
|
|
||||||
|
let mut t = tuple_list!(1, "a");
|
||||||
|
|
||||||
|
tuple_for_each!(f1, std::fmt::Display, t, |x| {
|
||||||
|
println!("{}", x);
|
||||||
|
});
|
||||||
|
|
||||||
|
tuple_for_each_mut!(f2, std::fmt::Display, t, |x| {
|
||||||
|
println!("{}", x);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
// Define trait and implement it for several primitive types.
|
// Define trait and implement it for several primitive types.
|
||||||
|
@ -43,6 +43,8 @@ where
|
|||||||
fn count(&self) -> usize {
|
fn count(&self) -> usize {
|
||||||
self.entries().len()
|
self.entries().len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO implement a was_fuzzed counter
|
||||||
|
|
||||||
/// Add an entry to the corpus and return its index
|
/// Add an entry to the corpus and return its index
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -114,6 +114,17 @@ where
|
|||||||
pub fn pos(&self) -> usize {
|
pub fn pos(&self) -> usize {
|
||||||
self.pos
|
self.pos
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO maybe impl HasCorpus
|
||||||
|
#[inline]
|
||||||
|
pub fn corpus(&self) -> &C {
|
||||||
|
&self.corpus
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn corpus_mut(&mut self) -> &mut C {
|
||||||
|
&mut self.corpus
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user