@@ -75,53 +75,49 @@ pub trait Graph
75
75
type Directedness : Directedness ;
76
76
77
77
/// Returns copies of all current vertex values in the graph.
78
- fn all_vertices_weighted (
79
- & self ,
80
- ) -> Box < dyn ' _ + Iterator < Item = ( Self :: Vertex , & Self :: VertexWeight ) > > ;
78
+ fn all_vertices_weighted ( & self ) -> impl Iterator < Item = ( Self :: Vertex , & Self :: VertexWeight ) > ;
81
79
82
80
/// Returns the weights of all edges that are sourced in v1 and sinked in
83
81
/// v2. I.e. all edges where e == (v1,v2,_).
84
82
///
85
83
/// If the graph is undirected, returns all edges connecting the two
86
- /// vertices I.e. all edges where e == (v1,v2,_) or e == (v2,v1,_)
84
+ /// vertices. I.e. all edges where e == (v1,v2,_) or e == (v2,v1,_)
87
85
fn edges_between < ' a : ' b , ' b > (
88
86
& ' a self ,
89
87
source : impl ' b + Borrow < Self :: Vertex > ,
90
88
sink : impl ' b + Borrow < Self :: Vertex > ,
91
- ) -> Box < dyn ' b + Iterator < Item = & ' a Self :: EdgeWeight > > ;
89
+ ) -> impl ' b + Iterator < Item = & ' a Self :: EdgeWeight > ;
92
90
93
91
// Optional methods
94
92
95
93
/// Returns copies of all current edges in the graph.
96
- fn all_edges < ' a > (
97
- & ' a self ,
98
- ) -> Box < dyn ' a + Iterator < Item = ( Self :: Vertex , Self :: Vertex , & ' a Self :: EdgeWeight ) > >
94
+ fn all_edges (
95
+ & self ,
96
+ ) -> impl ' _ + Iterator < Item = ( Self :: Vertex , Self :: Vertex , & Self :: EdgeWeight ) >
99
97
{
100
98
let mut finished = Vec :: new ( ) ;
101
- Box :: new (
102
- self . all_vertices ( )
103
- . flat_map ( move |v| self . edges_sourced_in ( v) . map ( move |( v2, w) | ( v, v2, w) ) )
104
- . filter ( move |( so, si, _) | {
105
- if finished. last ( ) . is_none ( ) || finished. last ( ) . unwrap ( ) != so
106
- {
107
- finished. push ( so. clone ( ) ) ;
108
- }
109
-
110
- if !Self :: Directedness :: directed ( )
111
- {
112
- si == so || !finished. contains ( & si)
113
- }
114
- else
115
- {
116
- true
117
- }
118
- } ) ,
119
- )
99
+ self . all_vertices ( )
100
+ . flat_map ( move |v| self . edges_sourced_in ( v) . map ( move |( v2, w) | ( v, v2, w) ) )
101
+ . filter ( move |( so, si, _) | {
102
+ if finished. last ( ) . is_none ( ) || finished. last ( ) . unwrap ( ) != so
103
+ {
104
+ finished. push ( so. clone ( ) ) ;
105
+ }
106
+
107
+ if !Self :: Directedness :: directed ( )
108
+ {
109
+ si == so || !finished. contains ( & si)
110
+ }
111
+ else
112
+ {
113
+ true
114
+ }
115
+ } )
120
116
}
121
117
122
- fn all_vertices < ' a > ( & ' a self ) -> Box < dyn ' a + Iterator < Item = Self :: Vertex > >
118
+ fn all_vertices ( & self ) -> impl ' _ + Iterator < Item = Self :: Vertex >
123
119
{
124
- Box :: new ( self . all_vertices_weighted ( ) . map ( |( v, _) | v) )
120
+ self . all_vertices_weighted ( ) . map ( |( v, _) | v)
125
121
}
126
122
127
123
fn vertex_weight ( & self , v : impl Borrow < Self :: Vertex > ) -> Option < & Self :: VertexWeight >
@@ -141,9 +137,9 @@ pub trait Graph
141
137
iter. into_iter ( ) . all ( |v| self . contains_vertex ( v) )
142
138
}
143
139
144
- fn all_vertex_weights < ' a > ( & ' a self ) -> Box < dyn ' a + Iterator < Item = & ' a Self :: VertexWeight > >
140
+ fn all_vertex_weights ( & self ) -> impl ' _ + Iterator < Item = & Self :: VertexWeight >
145
141
{
146
- Box :: new ( self . all_vertices_weighted ( ) . map ( |( _, w) | w) )
142
+ self . all_vertices_weighted ( ) . map ( |( _, w) | w)
147
143
}
148
144
149
145
/// Returns the sink and weight of any edge sourced in the given vertex.
@@ -154,12 +150,12 @@ pub trait Graph
154
150
fn edges_sourced_in < ' a : ' b , ' b > (
155
151
& ' a self ,
156
152
v : impl ' b + Borrow < Self :: Vertex > ,
157
- ) -> Box < dyn ' b + Iterator < Item = ( Self :: Vertex , & ' a Self :: EdgeWeight ) > >
153
+ ) -> impl ' b + Iterator < Item = ( Self :: Vertex , & ' a Self :: EdgeWeight ) >
158
154
{
159
- Box :: new ( self . all_vertices ( ) . flat_map ( move |v2| {
155
+ self . all_vertices ( ) . flat_map ( move |v2| {
160
156
self . edges_between ( v. borrow ( ) . clone ( ) , v2. borrow ( ) . clone ( ) )
161
157
. map ( move |w| ( v2. clone ( ) , w) )
162
- } ) )
158
+ } )
163
159
}
164
160
165
161
/// Returns the source and weight of any edge sinked in the given vertex.
@@ -170,12 +166,12 @@ pub trait Graph
170
166
fn edges_sinked_in < ' a : ' b , ' b > (
171
167
& ' a self ,
172
168
v : impl ' b + Borrow < Self :: Vertex > ,
173
- ) -> Box < dyn ' b + Iterator < Item = ( Self :: Vertex , & ' a Self :: EdgeWeight ) > >
169
+ ) -> impl ' b + Iterator < Item = ( Self :: Vertex , & ' a Self :: EdgeWeight ) >
174
170
{
175
- Box :: new ( self . all_vertices ( ) . flat_map ( move |v2| {
171
+ self . all_vertices ( ) . flat_map ( move |v2| {
176
172
self . edges_between ( v2. borrow ( ) . clone ( ) , v. borrow ( ) . clone ( ) )
177
173
. map ( move |w| ( v2. clone ( ) , w) )
178
- } ) )
174
+ } )
179
175
}
180
176
181
177
/// Returns the neighboring vertex and the weight of any edge incident
@@ -185,15 +181,11 @@ pub trait Graph
185
181
fn edges_incident_on < ' a : ' b , ' b > (
186
182
& ' a self ,
187
183
v : impl ' b + Borrow < Self :: Vertex > ,
188
- ) -> Box < dyn ' b + Iterator < Item = ( Self :: Vertex , & ' a Self :: EdgeWeight ) > >
184
+ ) -> impl ' b + Iterator < Item = ( Self :: Vertex , & ' a Self :: EdgeWeight ) >
189
185
{
190
- Box :: new (
191
- self . edges_sourced_in ( v. borrow ( ) . clone ( ) ) . chain (
192
- self . edges_sinked_in ( v. borrow ( ) . clone ( ) )
193
- . filter ( move |( v2, _) | {
194
- Self :: Directedness :: directed ( ) && v. borrow ( ) != v2. borrow ( )
195
- } ) ,
196
- ) ,
186
+ self . edges_sourced_in ( v. borrow ( ) . clone ( ) ) . chain (
187
+ self . edges_sinked_in ( v. borrow ( ) . clone ( ) )
188
+ . filter ( move |( v2, _) | Self :: Directedness :: directed ( ) && v. borrow ( ) != v2. borrow ( ) ) ,
197
189
)
198
190
}
199
191
@@ -202,12 +194,10 @@ pub trait Graph
202
194
fn vertex_neighbors < ' a : ' b , ' b > (
203
195
& ' a self ,
204
196
v : impl ' b + Borrow < Self :: Vertex > ,
205
- ) -> Box < dyn ' b + Iterator < Item = Self :: Vertex > >
197
+ ) -> impl ' b + Iterator < Item = Self :: Vertex >
206
198
{
207
- Box :: new (
208
- self . all_vertices ( )
209
- . filter ( move |other| self . neighbors ( v. borrow ( ) , other. borrow ( ) ) ) ,
210
- )
199
+ self . all_vertices ( )
200
+ . filter ( move |other| self . neighbors ( v. borrow ( ) , other. borrow ( ) ) )
211
201
}
212
202
213
203
/// Returns whether the two vertices are connected by an edge in any
@@ -235,13 +225,13 @@ pub trait GraphMut: Graph
235
225
{
236
226
fn all_vertices_weighted_mut (
237
227
& mut self ,
238
- ) -> Box < dyn ' _ + Iterator < Item = ( Self :: Vertex , & mut Self :: VertexWeight ) > > ;
228
+ ) -> impl ' _ + Iterator < Item = ( Self :: Vertex , & mut Self :: VertexWeight ) > ;
239
229
240
230
fn edges_between_mut < ' a : ' b , ' b > (
241
231
& ' a mut self ,
242
232
source : impl ' b + Borrow < Self :: Vertex > ,
243
233
sink : impl ' b + Borrow < Self :: Vertex > ,
244
- ) -> Box < dyn ' b + Iterator < Item = & ' a mut Self :: EdgeWeight > > ;
234
+ ) -> impl ' b + Iterator < Item = & ' a mut Self :: EdgeWeight > ;
245
235
246
236
// Optional methods
247
237
0 commit comments