use crate::future_wrapper::FutureWrapper;
use crate::{resolve::Path, Scope};
pub trait ScopeContainer<LABEL> {
type PathContainer;
fn lift_step(self, lbl: LABEL, prefix: Path<LABEL>) -> Self::PathContainer;
}
impl<LABEL: Copy> ScopeContainer<LABEL> for Vec<Scope> {
type PathContainer = Vec<Path<LABEL>>;
fn lift_step(self, lbl: LABEL, prefix: Path<LABEL>) -> Self::PathContainer {
self.into_iter()
.filter_map(move |s| prefix.step(lbl, s))
.collect()
}
}
impl<LABEL, SC: ScopeContainer<LABEL>, E> ScopeContainer<LABEL> for Result<SC, E> {
type PathContainer = Result<SC::PathContainer, E>;
fn lift_step(self, lbl: LABEL, prefix: Path<LABEL>) -> Self::PathContainer {
self.map(|sc| sc.lift_step(lbl, prefix))
}
}
impl<'rslv, LABEL, SC: ScopeContainer<LABEL> + Clone> ScopeContainer<LABEL>
for FutureWrapper<'rslv, SC>
where
LABEL: Copy,
SC::PathContainer: Clone,
Self: 'rslv,
LABEL: 'rslv,
{
type PathContainer = FutureWrapper<'rslv, SC::PathContainer>;
fn lift_step(self, lbl: LABEL, prefix: Path<LABEL>) -> Self::PathContainer {
FutureWrapper::new(async move { self.0.await.lift_step(lbl, prefix.clone()) })
}
}