use std::{collections::HashSet, hash::BuildHasher};
pub trait Iterable<T> {
type Iter<'a>: Iterator<Item = &'a T>
where
Self: 'a,
T: 'a;
fn iterable(&self) -> Self::Iter<'_>;
}
impl<T> Iterable<T> for T {
type Iter<'a>
= std::iter::Once<&'a T>
where
Self: 'a,
T: 'a;
fn iterable(&self) -> Self::Iter<'_> { std::iter::once(self) }
}
impl<T, S: BuildHasher> Iterable<T> for HashSet<T, S> {
type Iter<'a>
= std::collections::hash_set::Iter<'a, T>
where
Self: 'a,
T: 'a;
fn iterable(&self) -> Self::Iter<'_> { HashSet::iter(self) }
}
impl<T> Iterable<T> for Vec<T> {
type Iter<'a>
= std::slice::Iter<'a, T>
where
Self: 'a,
T: 'a;
fn iterable(&self) -> Self::Iter<'_> { (**self).iter() }
}