From c5b1f6fa7531d0d31411fa57b46a0c63c6343312 Mon Sep 17 00:00:00 2001 From: Aron Zwaan Date: Wed, 23 Oct 2024 16:42:04 +0200 Subject: [PATCH] WIP container trait bounds --- scopegraphs/src/containers/path.rs | 19 ++++--- scopegraphs/src/containers/scope.rs | 31 +++++++---- scopegraphs/src/lib.rs | 1 + scopegraphs/src/resolve/lookup.rs | 82 ++++++++++++++--------------- 4 files changed, 76 insertions(+), 57 deletions(-) diff --git a/scopegraphs/src/containers/path.rs b/scopegraphs/src/containers/path.rs index 043aa39..1129f7d 100644 --- a/scopegraphs/src/containers/path.rs +++ b/scopegraphs/src/containers/path.rs @@ -1,12 +1,16 @@ use crate::future_wrapper::FutureWrapper; -use crate::resolve::{Env, Path, ResolvedPath}; +use crate::resolve::{DataEquivalence, Env, Path, ResolvedPath}; use futures::future::join_all; use std::hash::Hash; +use std::fmt::Debug; + +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, DWFO>: Debug + 'rslv +{ /// Type returned by resolving a path to its sub-environment. - type EnvContainer; + type EnvContainer: EnvContainer<'sg, 'rslv, LABEL, DATA, DWFO>; /// Computes sub-environments for each path in the container. fn map_into_env) -> Self::EnvContainer>( @@ -15,11 +19,12 @@ 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> +impl<'rslv, 'sg, LABEL: Debug + 'sg, DATA: 'sg, DWFO> PathContainer<'sg, 'rslv, LABEL, DATA, DWFO> for Vec> where Self: 'rslv, LABEL: Clone + Hash + Eq, DATA: Hash + Eq, + Env<'sg, LABEL, DATA>: EnvContainer<'sg, 'rslv, LABEL, DATA, DWFO> { type EnvContainer = Env<'sg, LABEL, DATA>; @@ -30,13 +35,14 @@ 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> +impl<'rslv, 'sg, LABEL: Debug + 'sg, DATA: 'sg, E: Debug + 'rslv, DWFO> PathContainer<'sg, 'rslv, LABEL, DATA, DWFO> for Result>, E> where Self: 'rslv, LABEL: Clone + Hash, DATA: Hash, for<'a> ResolvedPath<'a, LABEL, DATA>: Hash + Eq, + Result, E>: EnvContainer<'sg, 'rslv, LABEL, DATA, DWFO> { type EnvContainer = Result, E>; @@ -49,12 +55,13 @@ where }) } } -impl<'sg, 'rslv, LABEL: 'sg, DATA: 'sg> PathContainer<'sg, 'rslv, LABEL, DATA> +impl<'sg, 'rslv, LABEL: 'sg, DATA: 'sg, DWFO> PathContainer<'sg, 'rslv, LABEL, DATA, DWFO> for FutureWrapper<'rslv, Vec>> where Self: 'rslv, LABEL: Clone + Hash, DATA: Hash, + FutureWrapper<'rslv, Env<'sg, LABEL, DATA>>: EnvContainer<'sg, 'rslv, LABEL, DATA, DWFO>, for<'a> ResolvedPath<'a, LABEL, DATA>: Hash + Eq, { type EnvContainer = FutureWrapper<'rslv, Env<'sg, LABEL, DATA>>; diff --git a/scopegraphs/src/containers/scope.rs b/scopegraphs/src/containers/scope.rs index 2986c4a..67a4884 100644 --- a/scopegraphs/src/containers/scope.rs +++ b/scopegraphs/src/containers/scope.rs @@ -1,20 +1,28 @@ +use std::hash::Hash; +use std::fmt::Debug; + use crate::future_wrapper::FutureWrapper; use crate::resolve::Path; use crate::Scope; +use super::PathContainer; + /// Interface for scope containers that support the operations required for query resolution. -pub trait ScopeContainer