@@ -1304,7 +1304,7 @@ impl<T> Graph<T>
13041304 labels_ptr. insert ( vertex_id. clone ( ) , label) ;
13051305 }
13061306
1307- self . labels . get ( vertex_id) . map ( |s| s . clone ( ) )
1307+ self . labels . get ( vertex_id) . cloned ( )
13081308 }
13091309
13101310 #[ cfg( feature = "dot" ) ]
@@ -1321,6 +1321,7 @@ impl<T> Graph<T>
13211321 /// let v1 = graph.add_vertex(0);
13221322 /// let v2 = graph.add_vertex(1);
13231323 /// let v3 = graph.add_vertex(2);
1324+ /// let v4 = graph.add_vertex(3);
13241325 ///
13251326 /// assert!(graph.label_vertex(&v1, &format!("V{}", vertex_id)).is_ok());
13261327 /// vertex_id += 1;
@@ -1334,7 +1335,7 @@ impl<T> Graph<T>
13341335 /// assert_eq!(graph.label(&v2).unwrap(), "V2");
13351336 /// assert_eq!(graph.label(&v3).unwrap(), "V3");
13361337 ///
1337- /// let new_labels: HashMap<VertexId, String> = vec![v1.clone(), v2.clone(), v3.clone()]
1338+ /// let new_labels: HashMap<VertexId, String> = vec![v1.clone(), v2.clone(), v3.clone(), v4.clone() ]
13381339 /// .iter()
13391340 /// .map(|id| {
13401341 /// vertex_id += 1;
@@ -1349,8 +1350,14 @@ impl<T> Graph<T>
13491350 /// assert_eq!(graph.label(&v1).unwrap(), "V4");
13501351 /// assert_eq!(graph.label(&v2).unwrap(), "V5");
13511352 /// assert_eq!(graph.label(&v3).unwrap(), "V6");
1353+ /// assert_eq!(graph.label(&v4).unwrap(), "V7");
13521354 /// ```
13531355 pub fn map_labels ( & mut self , mut fun : impl FnMut ( & VertexId , & str ) -> String ) {
1356+ // Initialize all labels
1357+ for ( v, _) in self . vertices . iter ( ) {
1358+ let _ = self . label ( v) ;
1359+ }
1360+
13541361 for ( id, l) in self . labels . iter_mut ( ) {
13551362 let new_label = fun ( id, l) ;
13561363 * l = new_label;
0 commit comments