diff --git a/scopegraphs/src/containers/env.rs b/scopegraphs/src/containers/env.rs index 990c68d..60e8e7a 100644 --- a/scopegraphs/src/containers/env.rs +++ b/scopegraphs/src/containers/env.rs @@ -1,7 +1,6 @@ use crate::future_wrapper::FutureWrapper; use crate::resolve::{Env, ResolvedPath}; use futures::future::Shared; -use futures::io::empty; use std::hash::Hash; use std::rc::Rc; @@ -12,7 +11,7 @@ pub trait EnvContainer<'sg, 'rslv, LABEL: 'sg, DATA: 'sg, DWFO>: /// Creates a new, container with an empty environment. fn empty() -> Self; - fn inject_if(data_ok: DWFO, path: ResolvedPath) -> Self; + fn inject_if(data_ok: DWFO, path: ResolvedPath<'sg, LABEL, DATA>) -> Self; /// Maps the current container to a new one, based a provided mapping of the underlying environment. fn flat_map( @@ -21,20 +20,20 @@ pub trait EnvContainer<'sg, 'rslv, LABEL: 'sg, DATA: 'sg, DWFO>: ) -> Self; } -impl<'sg: 'rslv, 'rslv, LABEL, DATA> EnvContainer<'sg, 'rslv, LABEL, DATA, bool> +impl<'sg: 'rslv, 'rslv, LABEL: Eq, DATA: Eq> EnvContainer<'sg, 'rslv, LABEL, DATA, bool> for Env<'sg, LABEL, DATA> where - ResolvedPath<'sg, LABEL, DATA>: Hash, + ResolvedPath<'sg, LABEL, DATA>: Hash + Clone, { fn empty() -> Self { Self::new() } - fn inject_if(data_ok: bool, path: ResolvedPath) -> Self { + fn inject_if(data_ok: bool, path: ResolvedPath<'sg, LABEL, DATA>) -> Self { if data_ok { return Env::single(path).into(); } else { - return empty(); + return Env::empty(); } } @@ -46,20 +45,22 @@ where } } -impl<'sg: 'rslv, 'rslv, LABEL: 'sg, DATA: 'sg> EnvContainer<'sg, 'rslv, LABEL, DATA, bool> +impl<'sg: 'rslv, 'rslv, LABEL, DATA> EnvContainer<'sg, 'rslv, LABEL, DATA, bool> for Rc> where ResolvedPath<'sg, LABEL, DATA>: Hash, + LABEL: 'sg + Eq + Clone, + DATA: 'sg + Eq, { fn empty() -> Self { Self::new(Env::empty()) } - fn inject_if(data_ok: bool, path: ResolvedPath) -> Self { + fn inject_if(data_ok: bool, path: ResolvedPath<'sg, LABEL, DATA>) -> Self { if data_ok { return Env::single(path).into(); } else { - return empty(); + return Env::empty().into(); } } @@ -80,22 +81,22 @@ impl<'sg, LABEL: 'sg, DATA: 'sg, E> From> } } -impl<'sg: 'rslv, 'rslv, LABEL: 'sg, DATA: 'sg, E: 'rslv> +impl<'sg: 'rslv, 'rslv, LABEL: 'sg + Eq, DATA: 'sg + Eq, E: 'rslv> EnvContainer<'sg, 'rslv, LABEL, DATA, Result> for Result, E> where - ResolvedPath<'sg, LABEL, DATA>: Hash, + ResolvedPath<'sg, LABEL, DATA>: Hash + Clone, E: Clone, { fn empty() -> Self { Ok(Env::empty()) } - fn inject_if(data_ok: Result, path: ResolvedPath) -> Self { + fn inject_if(data_ok: Result, path: ResolvedPath<'sg, LABEL, DATA>) -> Self { data_ok.map(|ok| { if ok { return Env::single(path).into(); } else { - return empty(); + return Env::empty(); } }) } @@ -108,25 +109,29 @@ where } } -impl<'sg: 'rslv, 'rslv, LABEL: 'sg, DATA: 'sg> +impl<'sg: 'rslv, 'rslv, LABEL: 'sg + Eq, DATA: 'sg + Eq> EnvContainer<'sg, 'rslv, LABEL, DATA, FutureWrapper<'rslv, bool>> for FutureWrapper<'rslv, Env<'sg, LABEL, DATA>> where - ResolvedPath<'sg, LABEL, DATA>: Hash, + ResolvedPath<'sg, LABEL, DATA>: Hash + Clone, LABEL: Clone, { fn empty() -> Self { FutureWrapper::new(std::future::ready(Env::empty())) } - fn inject_if(data_ok: FutureWrapper<'rslv, bool>, path: ResolvedPath) -> Self { - data_ok.map(|ok| { + fn inject_if( + data_ok: FutureWrapper<'rslv, bool>, + path: ResolvedPath<'sg, LABEL, DATA>, + ) -> Self { + return FutureWrapper::new(async move { + let ok = data_ok.await; if ok { return Env::single(path).into(); } else { - return empty(); + return Env::empty(); } - }) + }); } fn flat_map( diff --git a/scopegraphs/src/resolve/lookup.rs b/scopegraphs/src/resolve/lookup.rs index 56f5e24..e088b2c 100644 --- a/scopegraphs/src/resolve/lookup.rs +++ b/scopegraphs/src/resolve/lookup.rs @@ -21,7 +21,7 @@ use crate::resolve::{ use crate::{Label, Scope, ScopeGraph}; use scopegraphs_regular_expressions::RegexMatcher; -impl<'sg: 'rslv, 'storage, 'rslv, LABEL, DATA, CMPL, PWF, DWF, DWFO, LO, DEq> Resolve<'sg, 'rslv> +impl<'sg: 'rslv, 'storage, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq> Resolve<'sg, 'rslv> for Query<'storage, 'sg, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq> where 'storage: 'sg, @@ -36,9 +36,10 @@ where 'rslv, LABEL, DATA, - >>::EnvContainer: EnvContainer<'sg, 'rslv, LABEL, DATA, DWFO> + Debug, + >>::EnvContainer: + EnvContainer<'sg, 'rslv, LABEL, DATA, >::Output> + Debug, PWF: for<'a> RegexMatcher<&'a LABEL> + 'rslv, - DWF: DataWellformedness + 'rslv, + DWF: DataWellformedness + 'rslv, // DWF : DataWellFormedNess LO: LabelOrder