@@ -4,6 +4,7 @@ use anyhow::{Context, Error};
44use krates:: petgraph as pg;
55use semver:: Version ;
66use std:: {
7+ borrow:: Cow ,
78 collections:: { btree_map:: Entry , BTreeMap , HashSet } ,
89 fmt,
910} ;
@@ -52,7 +53,7 @@ pub enum Style {
5253
5354#[ derive( Default ) ]
5455struct NodeAttributes < ' a > {
55- label : Option < & ' a str > ,
56+ label : Option < Cow < ' a , str > > ,
5657 shape : Option < Shape > ,
5758 style : Option < Style > ,
5859 color : Option < & ' static str > ,
@@ -219,8 +220,7 @@ pub(crate) fn create_graph(
219220
220221 while let Some ( nid) = node_stack. pop ( ) {
221222 let node = & graph[ nid] ;
222- let mut iditer = node. kid . repr . splitn ( 3 , ' ' ) ;
223- let name = iditer. next ( ) . unwrap ( ) ;
223+ let name = node. kid . name ( ) ;
224224
225225 match dupe_nodes. entry ( name) {
226226 Entry :: Occupied ( it) => {
@@ -268,27 +268,27 @@ pub(crate) fn create_graph(
268268 |node| {
269269 let node_weight = node. weight ( ) ;
270270
271- if let Some ( feat) = & node_weight. feature {
271+ if let Some ( feat) = node_weight. feature {
272272 NodeAttributes {
273- label : Some ( feat) ,
273+ label : Some ( feat. into ( ) ) ,
274274 shape : Some ( Shape :: diamond) ,
275275 ..Default :: default ( )
276276 }
277277 } else {
278- let repr = & node_weight. kid . repr ;
278+ let kid = node_weight. kid ;
279279
280- let mut i = repr. splitn ( 3 , ' ' ) ;
281- let name = i. next ( ) . unwrap ( ) ;
282- let _version = i. next ( ) . unwrap ( ) ;
283- let source = i. next ( ) . unwrap ( ) ;
280+ let name = kid. name ( ) ;
281+ let version = kid. version ( ) ;
282+ let source = kid. source ( ) ;
284283
285284 if dupe_nodes. contains_key ( name) {
286- let label =
287- if source != "(registry+https://github.com/rust-lang/crates.io-index)" {
288- & repr[ name. len ( ) + 1 ..]
289- } else {
290- & repr[ name. len ( ) + 1 ..repr. len ( ) - source. len ( ) - 1 ]
291- } ;
285+ // Add the source only if it is not crates.io
286+ let label = if source != "registry+https://github.com/rust-lang/crates.io-index"
287+ {
288+ format ! ( "{version} {source}" ) . into ( )
289+ } else {
290+ version. into ( )
291+ } ;
292292
293293 NodeAttributes {
294294 label : Some ( label) ,
@@ -299,7 +299,7 @@ pub(crate) fn create_graph(
299299 }
300300 } else {
301301 NodeAttributes {
302- label : Some ( & repr [ 0 ..repr . len ( ) - source . len ( ) - 1 ] ) ,
302+ label : Some ( format ! ( "{name} {version}" ) . into ( ) ) ,
303303 shape : Some ( Shape :: r#box) ,
304304 style : Some ( Style :: rounded) ,
305305 ..Default :: default ( )
0 commit comments