diff --git a/scopegraphs/src/completeness/implicit.rs b/scopegraphs/src/completeness/implicit.rs index c6c62c8..2b8b8f3 100644 --- a/scopegraphs/src/completeness/implicit.rs +++ b/scopegraphs/src/completeness/implicit.rs @@ -14,7 +14,7 @@ use super::Implicit; /// Unlike [`ExplicitClose`](crate::completeness::ExplicitClose), this implementation will implicitly close edges once traversed. /// This does not require special attention from the type checker writer. /// -/// Returns [`EdgeClosedError`](EdgeClosedError) when an edge is added to a scope in which the label is already +/// Returns [EdgeClosedError] when an edge is added to a scope in which the label is already /// closed (because `get_edges(s, l, ...)` was called earlier. /// /// When edges are retrieved (e.g. during query resolution) the `(src, label)` edge is closed. diff --git a/scopegraphs/src/containers/path.rs b/scopegraphs/src/containers/path.rs index 043aa39..e3e5c7e 100644 --- a/scopegraphs/src/containers/path.rs +++ b/scopegraphs/src/containers/path.rs @@ -1,10 +1,13 @@ use crate::future_wrapper::FutureWrapper; use crate::resolve::{Env, Path, ResolvedPath}; use futures::future::join_all; +use std::fmt::Debug; use std::hash::Hash; +use super::EnvContainer; + /// Interface for path containers that support the operations required for query resolution. -pub trait PathContainer<'sg, 'rslv, LABEL: 'sg, DATA: 'sg>: 'rslv { +pub trait PathContainer<'sg, 'rslv, LABEL: 'sg, DATA: 'sg>: Debug + 'rslv { /// Type returned by resolving a path to its sub-environment. type EnvContainer; @@ -15,7 +18,26 @@ pub trait PathContainer<'sg, 'rslv, LABEL: 'sg, DATA: 'sg>: 'rslv { ) -> Self::EnvContainer; } -impl<'rslv, 'sg, LABEL: 'sg, DATA: 'sg> PathContainer<'sg, 'rslv, LABEL, DATA> for Vec> +/// Trait that is auto-implemented for any [PathContainer] implementation that yields a valid [EnvContainer]. +pub trait PathContainerWf<'sg, 'rslv, LABEL: 'sg, DATA: 'sg, DWFO>: + PathContainer<'sg, 'rslv, LABEL, DATA, EnvContainer = Self::EnvContainerWf> +{ + /// Witness that ```Self::EnvContainer``` is a valid environment container. + type EnvContainerWf: EnvContainer<'sg, 'rslv, LABEL, DATA, DWFO>; +} + +impl<'sg, 'rslv, LABEL, DATA, DWFO, T> PathContainerWf<'sg, 'rslv, LABEL, DATA, DWFO> for T +where + LABEL: Debug + 'sg, + DATA: 'sg, + T: PathContainer<'sg, 'rslv, LABEL, DATA>, + Self::EnvContainer: EnvContainer<'sg, 'rslv, LABEL, DATA, DWFO>, +{ + type EnvContainerWf = Self::EnvContainer; +} + +impl<'rslv, 'sg, LABEL: Debug + 'sg, DATA: 'sg> PathContainer<'sg, 'rslv, LABEL, DATA> + for Vec> where Self: 'rslv, LABEL: Clone + Hash + Eq, @@ -30,8 +52,8 @@ where // TODO: can this be generalized to arbitrary results of PathContainers? // (challenge is converting between the different `::EnvContainer`s.) -impl<'rslv, 'sg, LABEL: 'sg, DATA: 'sg, E: 'rslv> PathContainer<'sg, 'rslv, LABEL, DATA> - for Result>, E> +impl<'rslv, 'sg, LABEL: Debug + 'sg, DATA: 'sg, E: Debug + 'rslv> + PathContainer<'sg, 'rslv, LABEL, DATA> for Result>, E> where Self: 'rslv, LABEL: Clone + Hash, diff --git a/scopegraphs/src/containers/scope.rs b/scopegraphs/src/containers/scope.rs index 2986c4a..3edca07 100644 --- a/scopegraphs/src/containers/scope.rs +++ b/scopegraphs/src/containers/scope.rs @@ -1,9 +1,14 @@ +use std::fmt::Debug; +use std::hash::Hash; + use crate::future_wrapper::FutureWrapper; use crate::resolve::Path; use crate::Scope; +use super::{PathContainer, PathContainerWf}; + /// Interface for scope containers that support the operations required for query resolution. -pub trait ScopeContainer