1
- use crate :: { future_wrapper:: FutureWrapper , resolve:: { Env , Path , ResolvedPath } } ;
2
- use std:: { future:: { poll_fn, Future } , hash:: Hash , task:: Poll } ;
1
+ use crate :: {
2
+ future_wrapper:: FutureWrapper ,
3
+ resolve:: { Env , Path , ResolvedPath } ,
4
+ } ;
3
5
use futures:: future:: join_all;
6
+ use std:: hash:: Hash ;
4
7
5
8
/// Interface for path containers that support the operations required for query resolution.
6
- pub trait PathContainer < LABEL , DATA > {
9
+ pub trait PathContainer < ' sg , ' rslv , LABEL : ' sg , DATA : ' sg > : ' rslv {
7
10
/// Type returned by resolving a path to its sub-environment.
8
- type EnvContainer < ' sg >
11
+ type EnvContainer < ' env >
9
12
where
10
- DATA : ' sg ,
11
- LABEL : ' sg ;
13
+ ' sg : ' env ;
12
14
13
15
/// Computes sub-environments for each path in the container,
14
16
/// and composes them using the [`crate::containers::EnvContainer::lift_merge`] method.
15
- fn map_into_env < ' sg , F : FnMut ( Path < LABEL > ) -> Self :: EnvContainer < ' sg > > (
17
+ fn map_into_env < ' env , F : ' rslv + FnMut ( Path < LABEL > ) -> Self :: EnvContainer < ' env > > (
16
18
self ,
17
19
f : F ,
18
- ) -> Self :: EnvContainer < ' sg > ;
20
+ ) -> Self :: EnvContainer < ' env >
21
+ where
22
+ ' sg : ' env ;
19
23
}
20
24
21
- impl < LABEL , DATA > PathContainer < LABEL , DATA > for Vec < Path < LABEL > >
25
+ impl < ' rslv , ' sg , LABEL : ' sg , DATA : ' sg > PathContainer < ' sg , ' rslv , LABEL , DATA > for Vec < Path < LABEL > >
22
26
where
27
+ Self : ' rslv ,
23
28
LABEL : Clone + Hash + Eq ,
24
29
DATA : Hash + Eq ,
25
30
{
26
- type EnvContainer < ' sg > = Env < ' sg , LABEL , DATA > where LABEL : ' sg , DATA : ' sg ;
31
+ type EnvContainer < ' env > = Env < ' sg , LABEL , DATA > where ' sg : ' env ;
27
32
28
- fn map_into_env < ' sg , F : FnMut ( Path < LABEL > ) -> Self :: EnvContainer < ' sg > > (
33
+ fn map_into_env < ' env , F : FnMut ( Path < LABEL > ) -> Self :: EnvContainer < ' env > > (
29
34
self ,
30
35
f : F ,
31
- ) -> Self :: EnvContainer < ' sg > {
36
+ ) -> Self :: EnvContainer < ' env >
37
+ where
38
+ ' sg : ' env ,
39
+ {
32
40
self . into_iter ( ) . map ( f) . collect ( )
33
41
}
34
42
}
35
43
36
44
// TODO: can this be generalized to arbitrary results of PathContainers?
37
45
// (challenge is converting between the different `::EnvContainer`s.)
38
- impl < LABEL , DATA , E > PathContainer < LABEL , DATA > for Result < Vec < Path < LABEL > > , E >
46
+ impl < ' rslv , ' sg , LABEL : ' sg , DATA : ' sg , E : ' rslv > PathContainer < ' sg , ' rslv , LABEL , DATA >
47
+ for Result < Vec < Path < LABEL > > , E >
39
48
where
49
+ Self : ' rslv ,
40
50
LABEL : Clone + Hash + Eq ,
41
51
DATA : Hash ,
42
52
for < ' a > ResolvedPath < ' a , LABEL , DATA > : Hash + Eq ,
43
53
{
44
- type EnvContainer < ' sg > = Result < Env < ' sg , LABEL , DATA > , E > where DATA : ' sg , LABEL : ' sg ;
54
+ type EnvContainer < ' env > = Result < Env < ' sg , LABEL , DATA > , E > where ' sg : ' env ;
45
55
46
- fn map_into_env < ' sg , F : FnMut ( Path < LABEL > ) -> Self :: EnvContainer < ' sg > > (
56
+ fn map_into_env < ' env , F : FnMut ( Path < LABEL > ) -> Self :: EnvContainer < ' env > > (
47
57
self ,
48
58
f : F ,
49
- ) -> Self :: EnvContainer < ' sg > {
59
+ ) -> Self :: EnvContainer < ' env >
60
+ where
61
+ ' sg : ' env ,
62
+ {
50
63
self . and_then ( |paths| {
51
64
paths
52
65
. into_iter ( )
@@ -55,28 +68,30 @@ where
55
68
} )
56
69
}
57
70
}
58
- impl < ' fut , LABEL , DATA > PathContainer < LABEL , DATA > for FutureWrapper < ' fut , Vec < Path < LABEL > > >
71
+ impl < ' sg , ' rslv , LABEL : ' sg , DATA : ' sg > PathContainer < ' sg , ' rslv , LABEL , DATA >
72
+ for FutureWrapper < ' rslv , Vec < Path < LABEL > > >
59
73
where
74
+ Self : ' rslv ,
60
75
LABEL : Clone + Hash + Eq ,
61
76
DATA : Hash ,
62
77
for < ' a > ResolvedPath < ' a , LABEL , DATA > : Hash + Eq ,
63
78
{
64
- type EnvContainer < ' sg > = FutureWrapper < ' fut , Env < ' sg , LABEL , DATA > > where DATA : ' sg , LABEL : ' sg ;
79
+ type EnvContainer < ' env > = FutureWrapper < ' rslv , Env < ' sg , LABEL , DATA > > where ' sg : ' env ;
65
80
66
- fn map_into_env < ' sg , F : FnMut ( Path < LABEL > ) -> Self :: EnvContainer < ' sg > > (
81
+ fn map_into_env < ' env , F : ' rslv + FnMut ( Path < LABEL > ) -> Self :: EnvContainer < ' env > > (
67
82
self ,
68
83
f : F ,
69
- ) -> Self :: EnvContainer < ' sg > {
84
+ ) -> Self :: EnvContainer < ' sg >
85
+ where
86
+ ' sg : ' env ,
87
+ {
70
88
let p_self = Box :: pin ( self ) ;
71
89
let future = async move {
72
- let paths = p_self. await . clone ( ) ;
90
+ let paths = p_self. await ;
73
91
let env_futures = paths. into_iter ( ) . map ( f) ;
74
92
let envs = join_all ( env_futures) . await ;
75
93
envs. into_iter ( ) . collect :: < Env < _ , _ > > ( )
76
94
} ;
77
95
FutureWrapper ( Box :: new ( future) )
78
96
}
79
97
}
80
-
81
-
82
-
0 commit comments