I want to define a function every
which takes in an iterator and while it's not None
, makes sure that all values are true
.
Example applications:
every([true, true, true].into_iter()) == true
every([true, false, true].into_iter()) == false
I've had trouble getting it to work just with a Vec
, let alone an Iterator
. I've tried the following and a few variations but haven't gotten anywhere.
use std::ops;
fn every<T>(v: Vec<T>) -> bool
where
T: ops::Not,
{
for item in v {
match !item {
T::No => return false,
}
}
true
}
This code gets the error:
error[E0599]: no associated item named `No` found for type `T` in the current scope
--> src/lib.rs:9:13
|
9 | T::No => return false,
| ^^^^^ associated item not found in `T`