From 9d43f0cb8de9861be817024c98cf9ac6113dc8fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Tue, 29 Sep 2026 00:00:13 +0200 Subject: [PATCH] Move FromGrath trait within traits module --- src/traits.rs | 67 ++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/src/traits.rs b/src/traits.rs index 961f40a..45fce15 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -237,39 +237,6 @@ pub trait GraphTopologyDeletion: GraphTopology { fn delete_edge(&mut self, e: Self::Edge); } -/// A trait for constructing an undirected graph topology by converting another graph -/// implementation to this one. -pub trait FromGraph: GraphTopology { - /// Creates a new graph instance that is isomorphic to `source`. - /// - /// Returns the copied graph instance and two mappings from the vertices and edges of `source` - /// to the corresponding vertices and edges of the returned graph. - /// - /// # Examples - /// - /// ``` - /// use grapherity::prelude::*; - /// use grapherity::models::{AppendGraph, FrozenGraph}; - /// - /// let mut source = AppendGraph::new(); - /// let u = source.add_vertex(); - /// let v = source.add_vertex(); - /// let e = source.add_edge(u, v); - /// let (graph, vertex_map, edge_map) = FrozenGraph::from_graph(&source); - /// - /// assert!(graph.are_adjacent(vertex_map[u], vertex_map[v])); - /// ``` - fn from_graph( - source: &G, - ) -> ( - Self, - ElementMap, - ElementMap, - ) - where - Self: Sized; -} - /// A cursor for traversing the incidences of a vertex one step at a time. /// /// Because the cursor is [`Copy`], its state can be saved and restored to replay or branch a @@ -320,3 +287,37 @@ pub struct Incidence { /// The edge between *v* and [`vertex`](Self::vertex). pub edge: E, } + +// TODO-0.3.0: Provide and document a way to transform an ElementMap for source to an ElementMap for the copy. +/// A trait for constructing an undirected graph topology by converting another graph +/// implementation to this one. +pub trait FromGraph: GraphTopology { + /// Creates a new graph instance that is isomorphic to `source`. + /// + /// Returns the copied graph instance and two mappings from the vertices and edges of `source` + /// to the corresponding vertices and edges of the returned graph. + /// + /// # Examples + /// + /// ``` + /// use grapherity::prelude::*; + /// use grapherity::models::{AppendGraph, FrozenGraph}; + /// + /// let mut source = AppendGraph::new(); + /// let u = source.add_vertex(); + /// let v = source.add_vertex(); + /// let e = source.add_edge(u, v); + /// let (graph, vertex_map, edge_map) = FrozenGraph::from_graph(&source); + /// + /// assert!(graph.are_adjacent(vertex_map[u], vertex_map[v])); + /// ``` + fn from_graph( + source: &G, + ) -> ( + Self, + ElementMap, + ElementMap, + ) + where + Self: Sized; +}