From af572e385725daa4b2591bdf39cc661ab56b972d Mon Sep 17 00:00:00 2001 From: adamnemecek Date: Wed, 14 May 2025 13:44:47 -0700 Subject: [PATCH 1/9] clippy --- src/lib.rs | 119 ++++++++++++++++++++++++++--------------------------- 1 file changed, 58 insertions(+), 61 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8e28644..c270fcf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -325,16 +325,16 @@ pub enum Style { impl Style { pub fn as_slice(self) -> &'static str { match self { - Style::None => "", - Style::Solid => "solid", - Style::Dashed => "dashed", - Style::Dotted => "dotted", - Style::Bold => "bold", - Style::Rounded => "rounded", - Style::Diagonals => "diagonals", - Style::Filled => "filled", - Style::Striped => "striped", - Style::Wedged => "wedged", + Self::None => "", + Self::Solid => "solid", + Self::Dashed => "dashed", + Self::Dotted => "dotted", + Self::Bold => "bold", + Self::Rounded => "rounded", + Self::Diagonals => "diagonals", + Self::Filled => "filled", + Self::Striped => "striped", + Self::Wedged => "wedged", } } } @@ -352,10 +352,10 @@ pub enum RankDir { impl RankDir { pub fn as_slice(self) -> &'static str { match self { - RankDir::TopBottom => "TB", - RankDir::LeftRight => "LR", - RankDir::BottomTop => "BT", - RankDir::RightLeft => "RL", + Self::TopBottom => "TB", + Self::LeftRight => "LR", + Self::BottomTop => "BT", + Self::RightLeft => "RL", } } } @@ -412,7 +412,7 @@ impl<'a> Id<'a> { /// /// Passing an invalid string (containing spaces, brackets, /// quotes, ...) will return an empty `Err` value. - pub fn new>>(name: Name) -> Result, &'static str> { + pub fn new>>(name: Name) -> Result { let name = name.into(); { let mut chars = name.chars(); @@ -610,15 +610,15 @@ pub fn escape_html(s: &str) -> String { } impl<'a> LabelText<'a> { - pub fn label>>(s: S) -> LabelText<'a> { + pub fn label>>(s: S) -> Self { LabelStr(s.into()) } - pub fn escaped>>(s: S) -> LabelText<'a> { + pub fn escaped>>(s: S) -> Self { EscStr(s.into()) } - pub fn html>>(s: S) -> LabelText<'a> { + pub fn html>>(s: S) -> Self { HtmlStr(s.into()) } @@ -720,22 +720,22 @@ impl Arrow { } /// Arrow constructor which returns an empty arrow - pub fn none() -> Arrow { - Arrow { + pub fn none() -> Self { + Self { arrows: vec![NoArrow], } } /// Arrow constructor which returns a regular triangle arrow, without modifiers - pub fn normal() -> Arrow { - Arrow { + pub fn normal() -> Self { + Self { arrows: vec![ArrowShape::normal()], } } /// Arrow constructor which returns an arrow created by a given ArrowShape. - pub fn from_arrow(arrow: ArrowShape) -> Arrow { - Arrow { + pub fn from_arrow(arrow: ArrowShape) -> Self { + Self { arrows: vec![arrow], } } @@ -752,21 +752,21 @@ impl Arrow { impl From<[ArrowShape; 2]> for Arrow { fn from(val: [ArrowShape; 2]) -> Self { - Arrow { + Self { arrows: vec![val[0], val[1]], } } } impl From<[ArrowShape; 3]> for Arrow { fn from(val: [ArrowShape; 3]) -> Self { - Arrow { + Self { arrows: vec![val[0], val[1], val[2]], } } } impl From<[ArrowShape; 4]> for Arrow { fn from(val: [ArrowShape; 4]) -> Self { - Arrow { + Self { arrows: vec![val[0], val[1], val[2], val[3]], } } @@ -782,8 +782,8 @@ pub enum Fill { impl Fill { pub fn as_slice(self) -> &'static str { match self { - Fill::Open => "o", - Fill::Filled => "", + Self::Open => "o", + Self::Filled => "", } } } @@ -800,9 +800,9 @@ pub enum Side { impl Side { pub fn as_slice(self) -> &'static str { match self { - Side::Left => "l", - Side::Right => "r", - Side::Both => "", + Self::Left => "l", + Self::Right => "r", + Self::Both => "", } } } @@ -837,57 +837,57 @@ pub enum ArrowShape { } impl ArrowShape { /// Constructor which returns no arrow. - pub fn none() -> ArrowShape { + pub fn none() -> Self { NoArrow } /// Constructor which returns normal arrow. - pub fn normal() -> ArrowShape { + pub fn normal() -> Self { Normal(Fill::Filled, Side::Both) } /// Constructor which returns a regular box arrow. - pub fn boxed() -> ArrowShape { + pub fn boxed() -> Self { Box(Fill::Filled, Side::Both) } /// Constructor which returns a regular crow arrow. - pub fn crow() -> ArrowShape { + pub fn crow() -> Self { Crow(Side::Both) } /// Constructor which returns a regular curve arrow. - pub fn curve() -> ArrowShape { + pub fn curve() -> Self { Curve(Side::Both) } /// Constructor which returns an inverted curve arrow. - pub fn icurve() -> ArrowShape { + pub fn icurve() -> Self { ICurve(Fill::Filled, Side::Both) } /// Constructor which returns a diamond arrow. - pub fn diamond() -> ArrowShape { + pub fn diamond() -> Self { Diamond(Fill::Filled, Side::Both) } /// Constructor which returns a circle shaped arrow. - pub fn dot() -> ArrowShape { + pub fn dot() -> Self { Diamond(Fill::Filled, Side::Both) } /// Constructor which returns an inverted triangle arrow. - pub fn inv() -> ArrowShape { + pub fn inv() -> Self { Inv(Fill::Filled, Side::Both) } /// Constructor which returns a T shaped arrow. - pub fn tee() -> ArrowShape { + pub fn tee() -> Self { Tee(Side::Both) } /// Constructor which returns a V shaped arrow. - pub fn vee() -> ArrowShape { + pub fn vee() -> Self { Vee(Side::Both) } @@ -946,16 +946,16 @@ impl Kind { /// Determines which edge syntax must be used, and default style. fn keyword(&self) -> &'static str { match *self { - Kind::Digraph => "digraph", - Kind::Graph => "graph", + Self::Digraph => "digraph", + Self::Graph => "graph", } } /// The edgeop syntax to use for this graph kind. fn edgeop(&self) -> &'static str { match *self { - Kind::Digraph => "->", - Kind::Graph => "--", + Self::Digraph => "->", + Self::Graph => "--", } } } @@ -1117,7 +1117,7 @@ pub fn render_opts< let mut text = vec![source_id.as_slice()]; - let (source_port, source_direction) = g.source_port_position(&e); + let (source_port, source_direction) = g.source_port_position(e); if let Some(ref refinement) = source_port { text.push(":"); text.push(refinement.as_slice()); @@ -1128,7 +1128,7 @@ pub fn render_opts< } text.extend(&[" ", g.kind().edgeop(), " ", target_id.as_slice()]); - let (target_port, target_direction) = g.target_port_position(&e); + let (target_port, target_direction) = g.target_port_position(e); if let Some(ref refinement) = target_port { text.push(":"); text.push(refinement.as_slice()); @@ -1292,8 +1292,8 @@ mod tests { fn len(&self) -> usize { match self { &UnlabelledNodes(len) => len, - &AllNodesLabelled(ref lbls) => lbls.len(), - &SomeNodesLabelled(ref lbls) => lbls.len(), + AllNodesLabelled(lbls) => lbls.len(), + SomeNodesLabelled(lbls) => lbls.len(), } } } @@ -1304,9 +1304,9 @@ mod tests { node_labels: Trivial, edges: Vec, node_styles: Option>, - ) -> LabelledGraph { + ) -> Self { let count = node_labels.len(); - LabelledGraph { + Self { name, node_labels: node_labels.into_opt_strs(), edges, @@ -1323,8 +1323,8 @@ mod tests { name: &'static str, node_labels: Trivial, edges: Vec, - ) -> LabelledGraphWithEscStrs { - LabelledGraphWithEscStrs { + ) -> Self { + Self { graph: LabelledGraph::new(name, node_labels, edges, None), } } @@ -1712,10 +1712,7 @@ r#"digraph utf8_diagram { #[test] fn badly_formatted_id() { let id2 = Id::new("Weird { struct : ure } !!!"); - match id2 { - Ok(_) => panic!("graphviz id suddenly allows spaces, brackets and stuff"), - Err(..) => {} - } + if id2.is_ok() { panic!("graphviz id suddenly allows spaces, brackets and stuff") } } type SimpleEdge = (Node, Node); @@ -1735,9 +1732,9 @@ r#"digraph utf8_diagram { nodes: usize, edges: Vec, kind: Kind, - ) -> DefaultStyleGraph { + ) -> Self { assert!(!name.is_empty()); - DefaultStyleGraph { + Self { name, nodes, edges, From b0827220845cc0cffd0490917ee4d2229983f955 Mon Sep 17 00:00:00 2001 From: adamnemecek Date: Wed, 14 May 2025 13:46:05 -0700 Subject: [PATCH 2/9] use `assert!` instead of `panic!` --- src/lib.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c270fcf..4aed8a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1657,10 +1657,7 @@ r#"digraph utf8_diagram { #[test] fn simple_id_construction() { let id1 = Id::new("hello"); - match id1 { - Ok(_) => {} - Err(..) => panic!("'hello' is not a valid value for id anymore"), - } + assert!(id1.is_ok(), "'hello' is not a valid value for id anymore"), } #[test] @@ -1712,7 +1709,7 @@ r#"digraph utf8_diagram { #[test] fn badly_formatted_id() { let id2 = Id::new("Weird { struct : ure } !!!"); - if id2.is_ok() { panic!("graphviz id suddenly allows spaces, brackets and stuff") } + assert!(id2.is_ok(), "graphviz id suddenly allows spaces, brackets and stuff"); } type SimpleEdge = (Node, Node); From a2f9ef5845d55d484e8bb85a0dfa8c2bc2d980b7 Mon Sep 17 00:00:00 2001 From: adamnemecek Date: Wed, 14 May 2025 13:46:30 -0700 Subject: [PATCH 3/9] cargo fmt --- src/lib.rs | 67 +++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4aed8a8..64663d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -272,10 +272,10 @@ use self::LabelText::*; use std::borrow::Cow; -use std::io; -use std::str; use std::collections::HashMap; +use std::io; use std::io::Write; +use std::str; /// The text for a graphviz label on a node or edge. pub enum LabelText<'a> { @@ -552,8 +552,8 @@ pub trait Labeller<'a, N, E> { /// Specify a subpart of the source node for the origin of the edge (portname) and a /// direction for the edge (compass_point). See also - /// https://graphviz.org/docs/attr-types/portPos/. - /// + /// https://graphviz.org/docs/attr-types/portPos/. + /// /// For the portname to take effect the node shape must be `record`. See /// also https://graphviz.org/doc/info/shapes.html#record fn source_port_position(&'a self, _e: &E) -> (Option>, Option) { @@ -579,7 +579,7 @@ pub enum CompassPoint { W, NW, C, - Underscore + Underscore, } impl CompassPoint { @@ -1094,7 +1094,11 @@ pub fn render_opts< text.push("]"); } - let node_attrs = g.node_attrs(n).iter().map(|(name, value)| format!("[{name}={value}]")).collect::>(); + let node_attrs = g + .node_attrs(n) + .iter() + .map(|(name, value)| format!("[{name}={value}]")) + .collect::>(); text.extend(node_attrs.iter().map(|s| s as &str)); text.push(";"); @@ -1116,7 +1120,7 @@ pub fn render_opts< let target_id = g.node_id(&target); let mut text = vec![source_id.as_slice()]; - + let (source_port, source_direction) = g.source_port_position(e); if let Some(ref refinement) = source_port { text.push(":"); @@ -1126,8 +1130,7 @@ pub fn render_opts< text.push(":"); text.push(dir.as_str()); } - text.extend(&[" ", g.kind().edgeop(), " ", - target_id.as_slice()]); + text.extend(&[" ", g.kind().edgeop(), " ", target_id.as_slice()]); let (target_port, target_direction) = g.target_port_position(e); if let Some(ref refinement) = target_port { text.push(":"); @@ -1178,7 +1181,11 @@ pub fn render_opts< text.push("]"); } - let edge_attrs = g.edge_attrs(e).iter().map(|(name, value)| format!("[{name}={value}]")).collect::>(); + let edge_attrs = g + .edge_attrs(e) + .iter() + .map(|(name, value)| format!("[{name}={value}]")) + .collect::>(); text.extend(edge_attrs.iter().map(|s| s as &str)); text.push(";"); writeln(w, &text)?; @@ -1319,11 +1326,7 @@ mod tests { } impl LabelledGraphWithEscStrs { - fn new( - name: &'static str, - node_labels: Trivial, - edges: Vec, - ) -> Self { + fn new(name: &'static str, node_labels: Trivial, edges: Vec) -> Self { Self { graph: LabelledGraph::new(name, node_labels, edges, None), } @@ -1592,18 +1595,22 @@ mod tests { #[test] fn utf8_diagram() { - let labels = AllNodesLabelled(vec!("Λ", "ι")); - let r = test_input(LabelledGraph::new("utf8_diagram", - labels, - vec![edge(0, 1, "☕", Style::None, None)], - None)); - assert_eq!(r.unwrap(), -r#"digraph utf8_diagram { + let labels = AllNodesLabelled(vec!["Λ", "ι"]); + let r = test_input(LabelledGraph::new( + "utf8_diagram", + labels, + vec![edge(0, 1, "☕", Style::None, None)], + None, + )); + assert_eq!( + r.unwrap(), + r#"digraph utf8_diagram { N0[label="Λ"]; N1[label="ι"]; N0 -> N1[label="☕"]; } -"#); +"# + ); } #[test] @@ -1657,7 +1664,7 @@ r#"digraph utf8_diagram { #[test] fn simple_id_construction() { let id1 = Id::new("hello"); - assert!(id1.is_ok(), "'hello' is not a valid value for id anymore"), + assert!(id1.is_ok(), "'hello' is not a valid value for id anymore"); } #[test] @@ -1709,7 +1716,10 @@ r#"digraph utf8_diagram { #[test] fn badly_formatted_id() { let id2 = Id::new("Weird { struct : ure } !!!"); - assert!(id2.is_ok(), "graphviz id suddenly allows spaces, brackets and stuff"); + assert!( + id2.is_ok(), + "graphviz id suddenly allows spaces, brackets and stuff" + ); } type SimpleEdge = (Node, Node); @@ -1724,12 +1734,7 @@ r#"digraph utf8_diagram { } impl DefaultStyleGraph { - fn new( - name: &'static str, - nodes: usize, - edges: Vec, - kind: Kind, - ) -> Self { + fn new(name: &'static str, nodes: usize, edges: Vec, kind: Kind) -> Self { assert!(!name.is_empty()); Self { name, From bd68b4faf2efb5d269cbfd93adfb4d8af0bff8b6 Mon Sep 17 00:00:00 2001 From: adamnemecek Date: Wed, 14 May 2025 13:49:19 -0700 Subject: [PATCH 4/9] refactoring --- src/lib.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 64663d1..03ed95d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -835,6 +835,7 @@ pub enum ArrowShape { /// Arrow ending with a V shaped arrow. Vee(Side), } + impl ArrowShape { /// Constructor which returns no arrow. pub fn none() -> Self { @@ -913,19 +914,19 @@ impl ArrowShape { }, NoArrow => {} }; - match *self { - NoArrow => res.push_str("none"), - Normal(_, _) => res.push_str("normal"), - Box(_, _) => res.push_str("box"), - Crow(_) => res.push_str("crow"), - Curve(_) => res.push_str("curve"), - ICurve(_, _) => res.push_str("icurve"), - Diamond(_, _) => res.push_str("diamond"), - Dot(_) => res.push_str("dot"), - Inv(_, _) => res.push_str("inv"), - Tee(_) => res.push_str("tee"), - Vee(_) => res.push_str("vee"), - }; + res.push_str(match self { + NoArrow => "none", + Normal(_, _) => "normal", + Box(_, _) => "box", + Crow(_) => "crow", + Curve(_) => "curve", + ICurve(_, _) => "icurve", + Diamond(_, _) => "diamond", + Dot(_) => "dot", + Inv(_, _) => "inv", + Tee(_) => "tee", + Vee(_) => "vee", + }); res } } From d09dc840bbfe06455ba3f36d64e5d91861a32059 Mon Sep 17 00:00:00 2001 From: adamnemecek Date: Wed, 14 May 2025 13:52:04 -0700 Subject: [PATCH 5/9] is_ok() -> is_err() --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 03ed95d..695ef34 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1718,7 +1718,7 @@ mod tests { fn badly_formatted_id() { let id2 = Id::new("Weird { struct : ure } !!!"); assert!( - id2.is_ok(), + id2.is_err(), "graphviz id suddenly allows spaces, brackets and stuff" ); } From 9a1e902d1d071942771e3a7b3bdca5c1383362f6 Mon Sep 17 00:00:00 2001 From: adamnemecek Date: Wed, 14 May 2025 13:54:19 -0700 Subject: [PATCH 6/9] as_slice() -> as_str() --- src/lib.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 695ef34..020072d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -323,7 +323,7 @@ pub enum Style { } impl Style { - pub fn as_slice(self) -> &'static str { + pub fn as_str(self) -> &'static str { match self { Self::None => "", Self::Solid => "solid", @@ -350,7 +350,7 @@ pub enum RankDir { } impl RankDir { - pub fn as_slice(self) -> &'static str { + pub fn as_str(self) -> &'static str { match self { Self::TopBottom => "TB", Self::LeftRight => "LR", @@ -434,7 +434,7 @@ impl<'a> Id<'a> { } } - pub fn as_slice(&'a self) -> &'a str { + pub fn as_str(&'a self) -> &'a str { &self.name } @@ -780,7 +780,7 @@ pub enum Fill { } impl Fill { - pub fn as_slice(self) -> &'static str { + pub fn as_str(self) -> &'static str { match self { Self::Open => "o", Self::Filled => "", @@ -798,7 +798,7 @@ pub enum Side { } impl Side { - pub fn as_slice(self) -> &'static str { + pub fn as_str(self) -> &'static str { match self { Self::Left => "l", Self::Right => "r", @@ -901,15 +901,15 @@ impl ArrowShape { | Diamond(fill, side) | Inv(fill, side) | Normal(fill, side) => { - res.push_str(fill.as_slice()); + res.push_str(fill.as_str()); match side { - Side::Left | Side::Right => res.push_str(side.as_slice()), + Side::Left | Side::Right => res.push_str(side.as_str()), Side::Both => {} }; } - Dot(fill) => res.push_str(fill.as_slice()), + Dot(fill) => res.push_str(fill.as_str()), Crow(side) | Curve(side) | Tee(side) | Vee(side) => match side { - Side::Left | Side::Right => res.push_str(side.as_slice()), + Side::Left | Side::Right => res.push_str(side.as_str()), Side::Both => {} }, NoArrow => {} @@ -1043,11 +1043,11 @@ pub fn render_opts< w.write_all(b" ") } - writeln(w, &[g.kind().keyword(), " ", g.graph_id().as_slice(), " {"])?; + writeln(w, &[g.kind().keyword(), " ", g.graph_id().as_str(), " {"])?; if g.kind() == Kind::Digraph { if let Some(rankdir) = g.rank_dir() { indent(w)?; - writeln(w, &["rankdir=\"", rankdir.as_slice(), "\";"])?; + writeln(w, &["rankdir=\"", rankdir.as_str(), "\";"])?; } } @@ -1063,7 +1063,7 @@ pub fn render_opts< let escaped = &g.node_label(n).to_dot_string(); let shape; - let mut text = vec![id.as_slice()]; + let mut text = vec![id.as_str()]; if !options.contains(&RenderOption::NoNodeLabels) { text.push("[label="); @@ -1074,7 +1074,7 @@ pub fn render_opts< let style = g.node_style(n); if !options.contains(&RenderOption::NoNodeStyles) && style != Style::None { text.push("[style=\""); - text.push(style.as_slice()); + text.push(style.as_str()); text.push("\"]"); } @@ -1120,22 +1120,22 @@ pub fn render_opts< let source_id = g.node_id(&source); let target_id = g.node_id(&target); - let mut text = vec![source_id.as_slice()]; + let mut text = vec![source_id.as_str()]; let (source_port, source_direction) = g.source_port_position(e); if let Some(ref refinement) = source_port { text.push(":"); - text.push(refinement.as_slice()); + text.push(refinement.as_str()); } if let Some(dir) = source_direction { text.push(":"); text.push(dir.as_str()); } - text.extend(&[" ", g.kind().edgeop(), " ", target_id.as_slice()]); + text.extend(&[" ", g.kind().edgeop(), " ", target_id.as_str()]); let (target_port, target_direction) = g.target_port_position(e); if let Some(ref refinement) = target_port { text.push(":"); - text.push(refinement.as_slice()); + text.push(refinement.as_str()); } if let Some(dir) = target_direction { text.push(":"); @@ -1151,7 +1151,7 @@ pub fn render_opts< let style = g.edge_style(e); if !options.contains(&RenderOption::NoEdgeStyles) && style != Style::None { text.push("[style=\""); - text.push(style.as_slice()); + text.push(style.as_str()); text.push("\"]"); } From 464c04b658d725f3b039ede92c1f1524fa4adcaa Mon Sep 17 00:00:00 2001 From: adamnemecek Date: Wed, 14 May 2025 13:55:24 -0700 Subject: [PATCH 7/9] remove unneded dereferencing --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 020072d..ef7496d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -895,7 +895,7 @@ impl ArrowShape { /// Function which renders given ArrowShape into a String for displaying. pub fn to_dot_string(&self) -> String { let mut res = String::new(); - match *self { + match self { Box(fill, side) | ICurve(fill, side) | Diamond(fill, side) @@ -946,7 +946,7 @@ impl Kind { /// The keyword to use to introduce the graph. /// Determines which edge syntax must be used, and default style. fn keyword(&self) -> &'static str { - match *self { + match self { Self::Digraph => "digraph", Self::Graph => "graph", } @@ -954,7 +954,7 @@ impl Kind { /// The edgeop syntax to use for this graph kind. fn edgeop(&self) -> &'static str { - match *self { + match self { Self::Digraph => "->", Self::Graph => "--", } From f5fb181ce9aa28e0458b8fe19f3b831289839868 Mon Sep 17 00:00:00 2001 From: adamnemecek Date: Wed, 14 May 2025 13:57:12 -0700 Subject: [PATCH 8/9] use matches! --- src/lib.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ef7496d..e54845d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -902,16 +902,16 @@ impl ArrowShape { | Inv(fill, side) | Normal(fill, side) => { res.push_str(fill.as_str()); - match side { - Side::Left | Side::Right => res.push_str(side.as_str()), - Side::Both => {} - }; + if matches!(side, Side::Left | Side::Right) { + res.push_str(side.as_str()); + } } Dot(fill) => res.push_str(fill.as_str()), - Crow(side) | Curve(side) | Tee(side) | Vee(side) => match side { - Side::Left | Side::Right => res.push_str(side.as_str()), - Side::Both => {} - }, + Crow(side) | Curve(side) | Tee(side) | Vee(side) => { + if matches!(side, Side::Left | Side::Right) { + res.push_str(side.as_str()); + } + } NoArrow => {} }; res.push_str(match self { From f906dcf2950743cc314a916e6b8e6c7e25d1ec29 Mon Sep 17 00:00:00 2001 From: adamnemecek Date: Wed, 14 May 2025 14:02:05 -0700 Subject: [PATCH 9/9] merge Some --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e54845d..50bffdb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1386,7 +1386,7 @@ mod tests { } fn node_color(&'a self, n: &Node) -> Option> { match self.graph.node_color(n) { - Some(LabelStr(s)) | Some(EscStr(s)) | Some(HtmlStr(s)) => Some(EscStr(s)), + Some(LabelStr(s) | EscStr(s) | HtmlStr(s)) => Some(EscStr(s)), None => None, } } @@ -1397,7 +1397,7 @@ mod tests { } fn edge_color(&'a self, e: &&'a Edge) -> Option> { match self.graph.edge_color(e) { - Some(LabelStr(s)) | Some(EscStr(s)) | Some(HtmlStr(s)) => Some(EscStr(s)), + Some(LabelStr(s) | EscStr(s) | HtmlStr(s)) => Some(EscStr(s)), None => None, } }