pub trait DisposeWith<W> {
fn dispose_with(self, with: W);
}
impl<W, F: FnOnce(W)> DisposeWith<W> for F {
fn dispose_with(self, with: W) { self(with); }
}
pub trait DisposeIteratorWith<W> {
fn dispose_iter_with(self, with: W);
}
impl<W: Copy, I: IntoIterator> DisposeIteratorWith<W> for I
where I::Item: DisposeWith<W>
{
fn dispose_iter_with(self, with: W) {
for el in self {
el.dispose_with(with);
}
}
}
impl<W, T> DisposeWith<W> for Vec<T>
where Vec<T>: DisposeIteratorWith<W>
{
fn dispose_with(self, with: W) { self.dispose_iter_with(with) }
}
impl<W, T> DisposeWith<W> for Box<[T]>
where Vec<T>: DisposeIteratorWith<W>
{
fn dispose_with(self, with: W) { self.into_vec().dispose_iter_with(with) }
}
impl<'a, W, T> DisposeWith<W> for &'a [T]
where &'a [T]: DisposeIteratorWith<W>
{
fn dispose_with(self, with: W) { self.dispose_iter_with(with) }
}