pub trait Product {
fn name(&self) -> &str;
fn set_name(&mut self, name: String);
}
pub trait ProductIterator {
type Item<'this>: Product
where
Self: 'this;
fn next(&mut self) -> Option<Self::Item<'_>>;
}
pub trait Store {
type Product<'this>: Product
where
Self: 'this;
fn products<'product, 'iterator: 'product, 'this: 'iterator>(
&'this mut self,
) -> impl ProductIterator<Item<'product> = Self::Product<'product>> + 'iterator;
}
impl<I> ProductIterator for I
where
I: Iterator<Item: Product>,
{
type Item<'this> = I::Item
where
Self: 'this;
fn next(&mut self) -> Option<Self::Item<'_>> {
Iterator::next(self)
}
}
impl<'a, S> Store for &'a mut S
where
S: Store,
{
type Product<'this> = S::Product<'this>
where
Self: 'this;
fn products<'product, 'iterator: 'product, 'this: 'iterator>(
&'this mut self,
) -> impl ProductIterator<Item<'product> = Self::Product<'product>> + 'iterator {
Store::products(*self)
}
}