use dyn_clone::DynClone;
use std::fmt::Debug;
use std::hash::Hash;
pub trait Move: Copy + Debug + Eq + PartialEq + Hash + Send + Sized + Sync + 'static {}
impl<T: Copy + Debug + Eq + Hash + Send + Sync + 'static> Move for T {}
#[derive(Clone)]
pub struct PossibleMoves<'a, M> {
iterator: Box<dyn CloneableIterator<M> + Send + Sync + 'a>,
}
impl<'a, M: Move> PossibleMoves<'a, M> {
pub fn new(iterator: impl Clone + Iterator<Item = M> + Send + Sync + 'a) -> Self {
PossibleMoves {
iterator: Box::new(iterator),
}
}
pub fn from_vec(moves: Vec<M>) -> Self {
PossibleMoves::new(moves.into_iter())
}
}
impl<'a, M> Iterator for PossibleMoves<'a, M> {
type Item = M;
fn next(&mut self) -> Option<M> {
self.iterator.next()
}
}
trait CloneableIterator<T>: DynClone + Iterator<Item = T> {}
impl<T, I: DynClone + Iterator<Item = T>> CloneableIterator<T> for I {}
dyn_clone::clone_trait_object!(<I> CloneableIterator<I>);
#[cfg(test)]
mod tests {
use super::*;
use impls::impls;
use test_log::test;
#[test]
fn possible_moves_is_send_sync() {
assert!(impls!(PossibleMoves<'_, ()>: Send & Sync));
}
}