diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index c220600..863b329 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -34,7 +34,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - rust-version: [nightly-2020-11-25] + rust-version: [nightly-2024-10-28] steps: - uses: actions/checkout@v2 diff --git a/src/algo/tarjan_scc.rs b/src/algo/tarjan_scc.rs index 579631a..2b84fc5 100644 --- a/src/algo/tarjan_scc.rs +++ b/src/algo/tarjan_scc.rs @@ -218,7 +218,7 @@ where ); Self { dfs, - unchecked: graph.all_vertices(), + unchecked: Box::new(graph.all_vertices()), } } } diff --git a/src/common/adjacency_list/impl_graph.rs b/src/common/adjacency_list/impl_graph.rs index d718f81..95f17a5 100644 --- a/src/common/adjacency_list/impl_graph.rs +++ b/src/common/adjacency_list/impl_graph.rs @@ -16,56 +16,52 @@ where type Vertex = usize; type VertexWeight = Vw; - fn all_vertices_weighted( - &self, - ) -> Box> + fn all_vertices_weighted(&self) -> impl Iterator { - Box::new(self.vertices.iter().enumerate().map(|(v, (w, _))| (v, w))) + self.vertices.iter().enumerate().map(|(v, (w, _))| (v, w)) } fn edges_between<'a: 'b, 'b>( &'a self, source: impl 'b + Borrow, sink: impl 'b + Borrow, - ) -> Box> + ) -> impl 'b + Iterator { let source = source.borrow().clone(); let sink = sink.borrow().clone(); - Box::new( - self.vertices - .get(source) - .into_iter() - .flat_map(move |(_, edges)| { - edges.iter().filter_map(move |(si, w)| { - if *si == sink - { - Some(w) - } - else - { - None - } - }) + self.vertices + .get(source) + .into_iter() + .flat_map(move |(_, edges)| { + edges.iter().filter_map(move |(si, w)| { + if *si == sink + { + Some(w) + } + else + { + None + } }) - .chain( - self.vertices - .get(sink) - .into_iter() - .flat_map(move |(_, edges)| { - edges.iter().filter_map(move |(si, w)| { - if !Self::Directedness::directed() && *si != sink && *si == source - { - Some(w) - } - else - { - None - } - }) - }), - ), - ) + }) + .chain( + self.vertices + .get(sink) + .into_iter() + .flat_map(move |(_, edges)| { + edges.iter().filter_map(move |(si, w)| { + if !Self::Directedness::directed() && *si != sink && *si == source + { + Some(w) + } + else + { + None + } + }) + }), + ) } } @@ -73,65 +69,61 @@ impl GraphMut for AdjListGraph where D: Directedness, { - fn all_vertices_weighted_mut<'a>( - &'a mut self, - ) -> Box> + fn all_vertices_weighted_mut( + &mut self, + ) -> impl '_ + Iterator { - Box::new( - self.vertices - .iter_mut() - .enumerate() - .map(|(v, (w, _))| (v, w)), - ) + self.vertices + .iter_mut() + .enumerate() + .map(|(v, (w, _))| (v, w)) } fn edges_between_mut<'a: 'b, 'b>( &'a mut self, source: impl 'b + Borrow, sink: impl 'b + Borrow, - ) -> Box> + ) -> impl 'b + Iterator { let source = source.borrow().clone(); let sink = sink.borrow().clone(); - Box::new( - self.vertices - .iter_mut() - .enumerate() - .filter_map(move |(so, (_, edges))| { - if source == so - { - Some((false, edges)) - } - else if !Self::Directedness::directed() && (so == sink) - { - Some((true, edges)) - } - else - { - None - } - }) - .flat_map(|(sink_first, edges)| { - edges - .iter_mut() - .map(move |(si, weight)| (sink_first, si, weight)) - }) - .filter_map(move |(sink_first, si, weight)| { - if sink_first - { - if source == *si - { - return Some(weight); - } - } - else if sink == *si + self.vertices + .iter_mut() + .enumerate() + .filter_map(move |(so, (_, edges))| { + if source == so + { + Some((false, edges)) + } + else if !Self::Directedness::directed() && (so == sink) + { + Some((true, edges)) + } + else + { + None + } + }) + .flat_map(|(sink_first, edges)| { + edges + .iter_mut() + .map(move |(si, weight)| (sink_first, si, weight)) + }) + .filter_map(move |(sink_first, si, weight)| { + if sink_first + { + if source == *si { return Some(weight); } - None - }), - ) + } + else if sink == *si + { + return Some(weight); + } + None + }) } } diff --git a/src/core/graph.rs b/src/core/graph.rs index ab74790..f95fc60 100644 --- a/src/core/graph.rs +++ b/src/core/graph.rs @@ -75,53 +75,49 @@ pub trait Graph type Directedness: Directedness; /// Returns copies of all current vertex values in the graph. - fn all_vertices_weighted( - &self, - ) -> Box>; + fn all_vertices_weighted(&self) -> impl Iterator; /// Returns the weights of all edges that are sourced in v1 and sinked in /// v2. I.e. all edges where e == (v1,v2,_). /// /// If the graph is undirected, returns all edges connecting the two - /// vertices I.e. all edges where e == (v1,v2,_) or e == (v2,v1,_) + /// vertices. I.e. all edges where e == (v1,v2,_) or e == (v2,v1,_) fn edges_between<'a: 'b, 'b>( &'a self, source: impl 'b + Borrow, sink: impl 'b + Borrow, - ) -> Box>; + ) -> impl 'b + Iterator; // Optional methods /// Returns copies of all current edges in the graph. - fn all_edges<'a>( - &'a self, - ) -> Box> + fn all_edges( + &self, + ) -> impl '_ + Iterator { let mut finished = Vec::new(); - Box::new( - self.all_vertices() - .flat_map(move |v| self.edges_sourced_in(v).map(move |(v2, w)| (v, v2, w))) - .filter(move |(so, si, _)| { - if finished.last().is_none() || finished.last().unwrap() != so - { - finished.push(so.clone()); - } - - if !Self::Directedness::directed() - { - si == so || !finished.contains(&si) - } - else - { - true - } - }), - ) + self.all_vertices() + .flat_map(move |v| self.edges_sourced_in(v).map(move |(v2, w)| (v, v2, w))) + .filter(move |(so, si, _)| { + if finished.last().is_none() || finished.last().unwrap() != so + { + finished.push(so.clone()); + } + + if !Self::Directedness::directed() + { + si == so || !finished.contains(&si) + } + else + { + true + } + }) } - fn all_vertices<'a>(&'a self) -> Box> + fn all_vertices(&self) -> impl '_ + Iterator { - Box::new(self.all_vertices_weighted().map(|(v, _)| v)) + self.all_vertices_weighted().map(|(v, _)| v) } fn vertex_weight(&self, v: impl Borrow) -> Option<&Self::VertexWeight> @@ -141,9 +137,9 @@ pub trait Graph iter.into_iter().all(|v| self.contains_vertex(v)) } - fn all_vertex_weights<'a>(&'a self) -> Box> + fn all_vertex_weights(&self) -> impl '_ + Iterator { - Box::new(self.all_vertices_weighted().map(|(_, w)| w)) + self.all_vertices_weighted().map(|(_, w)| w) } /// Returns the sink and weight of any edge sourced in the given vertex. @@ -154,12 +150,12 @@ pub trait Graph fn edges_sourced_in<'a: 'b, 'b>( &'a self, v: impl 'b + Borrow, - ) -> Box> + ) -> impl 'b + Iterator { - Box::new(self.all_vertices().flat_map(move |v2| { + self.all_vertices().flat_map(move |v2| { self.edges_between(v.borrow().clone(), v2.borrow().clone()) .map(move |w| (v2.clone(), w)) - })) + }) } /// Returns the source and weight of any edge sinked in the given vertex. @@ -170,12 +166,12 @@ pub trait Graph fn edges_sinked_in<'a: 'b, 'b>( &'a self, v: impl 'b + Borrow, - ) -> Box> + ) -> impl 'b + Iterator { - Box::new(self.all_vertices().flat_map(move |v2| { + self.all_vertices().flat_map(move |v2| { self.edges_between(v2.borrow().clone(), v.borrow().clone()) .map(move |w| (v2.clone(), w)) - })) + }) } /// Returns the neighboring vertex and the weight of any edge incident @@ -185,15 +181,11 @@ pub trait Graph fn edges_incident_on<'a: 'b, 'b>( &'a self, v: impl 'b + Borrow, - ) -> Box> + ) -> impl 'b + Iterator { - Box::new( - self.edges_sourced_in(v.borrow().clone()).chain( - self.edges_sinked_in(v.borrow().clone()) - .filter(move |(v2, _)| { - Self::Directedness::directed() && v.borrow() != v2.borrow() - }), - ), + self.edges_sourced_in(v.borrow().clone()).chain( + self.edges_sinked_in(v.borrow().clone()) + .filter(move |(v2, _)| Self::Directedness::directed() && v.borrow() != v2.borrow()), ) } @@ -202,12 +194,10 @@ pub trait Graph fn vertex_neighbors<'a: 'b, 'b>( &'a self, v: impl 'b + Borrow, - ) -> Box> + ) -> impl 'b + Iterator { - Box::new( - self.all_vertices() - .filter(move |other| self.neighbors(v.borrow(), other.borrow())), - ) + self.all_vertices() + .filter(move |other| self.neighbors(v.borrow(), other.borrow())) } /// Returns whether the two vertices are connected by an edge in any @@ -235,13 +225,13 @@ pub trait GraphMut: Graph { fn all_vertices_weighted_mut( &mut self, - ) -> Box>; + ) -> impl '_ + Iterator; fn edges_between_mut<'a: 'b, 'b>( &'a mut self, source: impl 'b + Borrow, sink: impl 'b + Borrow, - ) -> Box>; + ) -> impl 'b + Iterator; // Optional methods diff --git a/src/core/property/directedness_ensurers.rs b/src/core/property/directedness_ensurers.rs index 3b73d5e..69f280a 100644 --- a/src/core/property/directedness_ensurers.rs +++ b/src/core/property/directedness_ensurers.rs @@ -29,13 +29,13 @@ impl Graph for DirectedGraph to self.0.graph() { fn all_vertices_weighted( &self, - ) -> Box>; + ) -> impl Iterator; fn edges_between<'a: 'b, 'b>( &'a self, source: impl 'b + Borrow, sink: impl 'b + Borrow, - ) -> Box>; + ) -> impl 'b + Iterator; } } } @@ -72,13 +72,13 @@ impl Graph for UndirectedGraph to self.0.graph() { fn all_vertices_weighted( &self, - ) -> Box>; + ) -> impl Iterator; fn edges_between<'a: 'b, 'b>( &'a self, source: impl 'b + Borrow, sink: impl 'b + Borrow, - ) -> Box>; + ) -> impl 'b + Iterator; } } } diff --git a/src/core/property/impl_ensurer.rs b/src/core/property/impl_ensurer.rs index 575b158..4986e50 100644 --- a/src/core/property/impl_ensurer.rs +++ b/src/core/property/impl_ensurer.rs @@ -246,13 +246,13 @@ macro_rules! impl_properties { to $crate::core::GraphDeref::graph(&self$($delegate)+){ fn all_vertices_weighted( &self, - ) -> Box>; + ) -> impl Iterator; fn edges_between<'a: 'b, 'b>( &'a self, source: impl 'b + std::borrow::Borrow, sink: impl 'b + std::borrow::Borrow, - ) -> Box>; + ) -> impl 'b + Iterator; } } } @@ -277,13 +277,13 @@ macro_rules! impl_properties { to $crate::core::GraphDerefMut::graph_mut(&mut self$($delegate)+) { fn all_vertices_weighted_mut( &mut self, - ) -> Box>; + ) -> impl '_ + Iterator; fn edges_between_mut<'a: 'b, 'b>( &'a mut self, source: impl 'b + std::borrow::Borrow, sink: impl 'b + std::borrow::Borrow, - ) -> Box>; + ) -> impl 'b + Iterator; } } } @@ -509,8 +509,8 @@ macro_rules! impl_properties { @implement { delegate::delegate!{ to $crate::core::GraphDeref::graph(&self$($delegate)+) { - fn exit_edges(&self) -> Box>; + fn exit_edges(&self) + -> impl '_ + Iterator; } } } diff --git a/src/core/property/subgraph.rs b/src/core/property/subgraph.rs index 0eaa8a1..001a11d 100644 --- a/src/core/property/subgraph.rs +++ b/src/core/property/subgraph.rs @@ -3,7 +3,7 @@ use crate::core::{Edge, Graph}; pub trait Subgraph: Graph { /// Edges who's sources are in this subgraph but who's sinks aren't. - fn exit_edges(&self) -> Box>; + fn exit_edges(&self) -> impl '_ + Iterator; /// Whether this subgraph can reach a vertex in the other subgraph, either /// by sharing a vertex with it, or having an axit edge to one of its diff --git a/src/core/proxy/edge_proxy.rs b/src/core/proxy/edge_proxy.rs index d7a459f..03268aa 100644 --- a/src/core/proxy/edge_proxy.rs +++ b/src/core/proxy/edge_proxy.rs @@ -57,7 +57,7 @@ impl Graph for EdgeProxyGraph to self.graph.graph() { fn all_vertices_weighted( &self, - ) -> Box>; + ) -> impl Iterator; } } @@ -65,7 +65,7 @@ impl Graph for EdgeProxyGraph &'a self, source: impl 'b + Borrow, sink: impl 'b + Borrow, - ) -> Box> + ) -> impl 'b + Iterator { let applicable = |so, si| { (source.borrow() == so && sink.borrow() == si) @@ -84,7 +84,7 @@ impl Graph for EdgeProxyGraph .count(); let underlying_count = self.graph.graph().edges_between(source, sink).count(); - Box::new((0..(underlying_count - removed_count + added_count)).map(|_| &())) + (0..(underlying_count - removed_count + added_count)).map(|_| &()) } } @@ -96,7 +96,7 @@ where to self.graph.graph_mut() { fn all_vertices_weighted_mut( &mut self, - ) -> Box>; + ) -> impl '_ + Iterator; } } @@ -104,13 +104,11 @@ where &'a mut self, source: impl 'b + Borrow, sink: impl 'b + Borrow, - ) -> Box> + ) -> impl 'b + Iterator { // Safe because &mut () can't mutate anything - Box::new( - self.edges_between(source, sink) - .map(|_| unsafe { &mut *UnsafeCell::new(()).get() }), - ) + self.edges_between(source, sink) + .map(|_| unsafe { &mut *UnsafeCell::new(()).get() }) } } diff --git a/src/core/proxy/reverse_graph.rs b/src/core/proxy/reverse_graph.rs index 9223a9f..e63ee4a 100644 --- a/src/core/proxy/reverse_graph.rs +++ b/src/core/proxy/reverse_graph.rs @@ -32,8 +32,8 @@ where delegate! { to self.0.graph() { - fn all_vertices_weighted(&self) -> Box>; + fn all_vertices_weighted(&self) -> + impl Iterator; } } @@ -41,7 +41,7 @@ where &'a self, source: impl 'b + Borrow, sink: impl 'b + Borrow, - ) -> Box> + ) -> impl 'b + Iterator { self.0.graph().edges_between(sink, source) } @@ -53,8 +53,8 @@ where { delegate! { to self.0.graph_mut() { - fn all_vertices_weighted_mut(&mut self) -> Box>; + fn all_vertices_weighted_mut(&mut self) + -> impl '_ + Iterator; } } @@ -62,9 +62,9 @@ where &'a mut self, source: impl 'b + Borrow, sink: impl 'b + Borrow, - ) -> Box> + ) -> impl 'b + Iterator { - Box::new(self.0.graph_mut().edges_between_mut(sink, source)) + self.0.graph_mut().edges_between_mut(sink, source) } } diff --git a/src/core/proxy/subgraph_proxy.rs b/src/core/proxy/subgraph_proxy.rs index 9af9244..aecf23b 100644 --- a/src/core/proxy/subgraph_proxy.rs +++ b/src/core/proxy/subgraph_proxy.rs @@ -69,32 +69,26 @@ impl Graph for SubgraphProxy type Vertex = ::Vertex; type VertexWeight = ::VertexWeight; - fn all_vertices_weighted( - &self, - ) -> Box> + fn all_vertices_weighted(&self) -> impl Iterator { - Box::new( - self.graph - .graph() - .all_vertices_weighted() - .filter(move |(v, _)| self.verts.contains(v)), - ) + self.graph + .graph() + .all_vertices_weighted() + .filter(move |(v, _)| self.verts.contains(v)) } fn edges_between<'a: 'b, 'b>( &'a self, source: impl 'b + Borrow, sink: impl 'b + Borrow, - ) -> Box> + ) -> impl 'b + Iterator { - Box::new( - self.graph - .graph() - .edges_between(source.borrow().clone(), sink.borrow().clone()) - .filter(move |_| { - self.contains_vertex(*source.borrow()) && self.contains_vertex(*sink.borrow()) - }), - ) + self.graph + .graph() + .edges_between(source.borrow().clone(), sink.borrow().clone()) + .filter(move |_| { + self.contains_vertex(*source.borrow()) && self.contains_vertex(*sink.borrow()) + }) } } @@ -102,34 +96,30 @@ impl GraphMut for SubgraphProxy where C::Graph: GraphMut, { - fn all_vertices_weighted_mut<'a>( - &'a mut self, - ) -> Box> + fn all_vertices_weighted_mut( + &mut self, + ) -> impl '_ + Iterator { let verts = &self.verts; let graph = self.graph.graph_mut(); - Box::new( - graph - .all_vertices_weighted_mut() - .filter(move |(v, _)| verts.contains(v)), - ) + graph + .all_vertices_weighted_mut() + .filter(move |(v, _)| verts.contains(v)) } fn edges_between_mut<'a: 'b, 'b>( &'a mut self, source: impl 'b + Borrow, sink: impl 'b + Borrow, - ) -> Box> + ) -> impl 'b + Iterator { let return_any = self.contains_vertex(*source.borrow()) && self.contains_vertex(*sink.borrow()); - Box::new( - self.graph - .graph_mut() - .edges_between_mut(source, sink) - .filter(move |_| return_any), - ) + self.graph + .graph_mut() + .edges_between_mut(source, sink) + .filter(move |_| return_any) } } @@ -221,9 +211,9 @@ where impl Subgraph for SubgraphProxy { - fn exit_edges<'a>(&'a self) -> Box> + fn exit_edges<'a>(&'a self) -> impl 'a + Iterator { - Box::new(self.exit_edges.iter().cloned()) + self.exit_edges.iter().cloned() } } diff --git a/src/core/proxy/undirected_proxy.rs b/src/core/proxy/undirected_proxy.rs index 2351887..33ce7d3 100644 --- a/src/core/proxy/undirected_proxy.rs +++ b/src/core/proxy/undirected_proxy.rs @@ -33,7 +33,7 @@ where to self.0.graph() { fn all_vertices_weighted( &self, - ) -> Box>; + ) -> impl Iterator; } } @@ -41,19 +41,17 @@ where &'a self, source: impl 'b + Borrow, sink: impl 'b + Borrow, - ) -> Box> + ) -> impl 'b + Iterator { - Box::new( - self.0 - .graph() - .edges_between(source.borrow().clone(), sink.borrow().clone()) - .chain( - self.0 - .graph() - .edges_between(sink.borrow().clone(), source.borrow().clone()) - .filter(move |_| source.borrow() != sink.borrow()), - ), - ) + self.0 + .graph() + .edges_between(source.borrow().clone(), sink.borrow().clone()) + .chain( + self.0 + .graph() + .edges_between(sink.borrow().clone(), source.borrow().clone()) + .filter(move |_| source.borrow() != sink.borrow()), + ) } } diff --git a/src/core/proxy/vertex_proxy.rs b/src/core/proxy/vertex_proxy.rs index a4c2196..a1575ba 100644 --- a/src/core/proxy/vertex_proxy.rs +++ b/src/core/proxy/vertex_proxy.rs @@ -50,58 +50,33 @@ impl Graph for VertexProxyGraph type Vertex = ProxyVertex<::Vertex>; type VertexWeight = (); - fn all_vertices_weighted( - &self, - ) -> Box> + fn all_vertices_weighted(&self) -> impl Iterator { - Box::new( - self.graph - .graph() - .all_vertices() - .filter(move |v| !self.removed.contains(v)) - .map(|v| (ProxyVertex::Underlying(v), &())) - .chain((0..self.new_count).map(|v| (ProxyVertex::New(v), &()))), - ) + self.graph + .graph() + .all_vertices() + .filter(move |v| !self.removed.contains(v)) + .map(|v| (ProxyVertex::Underlying(v), &())) + .chain((0..self.new_count).map(|v| (ProxyVertex::New(v), &()))) } fn edges_between<'a: 'b, 'b>( &'a self, source: impl 'b + Borrow, sink: impl 'b + Borrow, - ) -> Box> + ) -> impl 'b + Iterator { - struct EdgesBetween<'a, 'b, G> - where - 'a: 'b, - G: Graph, - { - edges_between: Option>>, - } - impl<'a, 'b, G> Iterator for EdgesBetween<'a, 'b, G> - where - 'a: 'b, - G: Graph, - { - type Item = &'a G::EdgeWeight; - - fn next(&mut self) -> Option - { - self.edges_between.as_mut()?.next() - } - } - - let result = match (source.borrow(), sink.borrow()) + match (source.borrow(), sink.borrow()) { (ProxyVertex::Underlying(so), ProxyVertex::Underlying(si)) if !(self.removed.contains(so) || self.removed.contains(si)) => { - Some(self.graph.graph().edges_between(so.clone(), si.clone())) + Some((so.clone(), si.clone())) }, _ => None, - }; - Box::new(EdgesBetween:: { - edges_between: result, - }) + } + .into_iter() + .flat_map(|(so, si)| self.graph.graph().edges_between(so, si)) } } diff --git a/tests/core/ensure.rs b/tests/core/ensure.rs index 0f7c7f7..9073019 100644 --- a/tests/core/ensure.rs +++ b/tests/core/ensure.rs @@ -72,17 +72,17 @@ impl Graph for MockEnsurer to self.0.graph() { fn all_vertices_weighted( &self, - ) -> Box>; + ) -> impl Iterator; fn all_edges( &self, - ) -> Box>; + ) -> impl '_ + Iterator; fn edges_between<'a: 'b, 'b>( &'a self, source: impl 'b + Borrow, sink: impl 'b + Borrow, - ) -> Box>; + ) -> impl 'b + Iterator; } } } @@ -94,13 +94,13 @@ where to self.0.graph_mut() { fn all_vertices_weighted_mut( &mut self, - ) -> Box>; + ) -> impl '_ + Iterator; fn edges_between_mut<'a: 'b, 'b>( &'a mut self, source: impl 'b + Borrow, sink: impl 'b + Borrow, - ) -> Box>; + ) -> impl 'b + Iterator; } } } @@ -173,17 +173,17 @@ impl Graph for MockUnloadedEnsurer to self.0.graph() { fn all_vertices_weighted( &self, - ) -> Box>; + ) -> impl Iterator; fn all_edges( &self, - ) -> Box>; + ) -> impl '_ + Iterator; fn edges_between<'a: 'b, 'b>( &'a self, source: impl 'b + Borrow, sink: impl 'b + Borrow, - ) -> Box>; + ) -> impl 'b + Iterator; } } } @@ -191,9 +191,9 @@ impl GraphMut for MockUnloadedEnsurer where C::Graph: GraphMut, { - fn all_vertices_weighted_mut<'a>( - &'a mut self, - ) -> Box> + fn all_vertices_weighted_mut( + &mut self, + ) -> impl '_ + Iterator { self.0.graph_mut().all_vertices_weighted_mut() } @@ -202,7 +202,7 @@ where &'a mut self, source: impl 'b + Borrow, sink: impl 'b + Borrow, - ) -> Box> + ) -> impl 'b + Iterator { self.0.graph_mut().edges_between_mut(source, sink) } diff --git a/tests/mock_graph/mock_graph.rs b/tests/mock_graph/mock_graph.rs index 2b914e1..10152cf 100644 --- a/tests/mock_graph/mock_graph.rs +++ b/tests/mock_graph/mock_graph.rs @@ -179,37 +179,31 @@ impl Graph for MockGraph type Vertex = MockVertex; type VertexWeight = MockVertexWeight; - fn all_vertices_weighted<'a>( - &'a self, - ) -> Box> + fn all_vertices_weighted(&self) -> impl Iterator { - Box::new( - self.vertices - .iter() - .map(|(&v, w)| (MockVertex { value: v }, w)), - ) + self.vertices + .iter() + .map(|(&v, w)| (MockVertex { value: v }, w)) } - fn all_edges<'a>( - &'a self, - ) -> Box> + fn all_edges( + &self, + ) -> impl '_ + Iterator { - Box::new( - self.edges - .iter() - .map(|(so, si, w)| (MockVertex { value: *so }, MockVertex { value: *si }, w)), - ) + self.edges + .iter() + .map(|(so, si, w)| (MockVertex { value: *so }, MockVertex { value: *si }, w)) } fn edges_between<'a: 'b, 'b>( &'a self, source: impl 'b + Borrow, sink: impl 'b + Borrow, - ) -> Box> + ) -> impl 'b + Iterator { let source = source.borrow().value; let sink = sink.borrow().value; - Box::new(self.edges.iter().filter_map(move |(so, si, w)| { + self.edges.iter().filter_map(move |(so, si, w)| { if (source == *so && sink == *si) || (!Self::Directedness::directed() && (source == *si && sink == *so)) { @@ -219,32 +213,30 @@ impl Graph for MockGraph { None } - })) + }) } } impl GraphMut for MockGraph { - fn all_vertices_weighted_mut<'a>( - &'a mut self, - ) -> Box> + fn all_vertices_weighted_mut( + &mut self, + ) -> impl '_ + Iterator { - Box::new( - self.vertices - .iter_mut() - .map(|(&v, w)| (MockVertex { value: v }, w)), - ) + self.vertices + .iter_mut() + .map(|(&v, w)| (MockVertex { value: v }, w)) } fn edges_between_mut<'a: 'b, 'b>( &'a mut self, source: impl 'b + Borrow, sink: impl 'b + Borrow, - ) -> Box> + ) -> impl 'b + Iterator { let source = source.borrow().value; let sink = sink.borrow().value; - Box::new(self.edges.iter_mut().filter_map(move |(so, si, w)| { + self.edges.iter_mut().filter_map(move |(so, si, w)| { if (source == *so && sink == *si) || (!Self::Directedness::directed() && (source == *si && sink == *so)) { @@ -254,7 +246,7 @@ impl GraphMut for MockGraph { None } - })) + }) } }