]> git.lizzy.rs Git - rust.git/commitdiff
rustfmt libgraphviz
authorNick Cameron <ncameron@mozilla.com>
Sat, 5 Sep 2015 03:44:26 +0000 (15:44 +1200)
committerNick Cameron <ncameron@mozilla.com>
Fri, 11 Sep 2015 08:41:08 +0000 (20:41 +1200)
src/libgraphviz/lib.rs

index 4b2c0189b6b46fb018e9d24b69277e2439f7acb8..76c79c1a1b0adda26f1022f5b72b5a2301d23e47 100644 (file)
@@ -413,8 +413,9 @@ pub fn new<Name: IntoCow<'a, str>>(name: Name) -> Result<Id<'a>, ()> {
         {
             let mut chars = name.chars();
             match chars.next() {
-                Some(c) if is_letter_or_underscore(c) => { ; },
-                _ => return Err(())
+                Some(c) if is_letter_or_underscore(c) => { ;
+                }
+                _ => return Err(()),
             }
             if !chars.all(is_constituent) {
                 return Err(())
@@ -505,24 +506,28 @@ pub fn escape_html(s: &str) -> String {
 }
 
 impl<'a> LabelText<'a> {
-    pub fn label<S:IntoCow<'a, str>>(s: S) -> LabelText<'a> {
+    pub fn label<S: IntoCow<'a, str>>(s: S) -> LabelText<'a> {
         LabelStr(s.into_cow())
     }
 
-    pub fn escaped<S:IntoCow<'a, str>>(s: S) -> LabelText<'a> {
+    pub fn escaped<S: IntoCow<'a, str>>(s: S) -> LabelText<'a> {
         EscStr(s.into_cow())
     }
 
-    pub fn html<S:IntoCow<'a, str>>(s: S) -> LabelText<'a> {
+    pub fn html<S: IntoCow<'a, str>>(s: S) -> LabelText<'a> {
         HtmlStr(s.into_cow())
     }
 
-    fn escape_char<F>(c: char, mut f: F) where F: FnMut(char) {
+    fn escape_char<F>(c: char, mut f: F)
+        where F: FnMut(char)
+    {
         match c {
             // not escaping \\, since Graphviz escString needs to
             // interpret backslashes; see EscStr above.
             '\\' => f(c),
-            _ => for c in c.escape_default() { f(c) }
+            _ => for c in c.escape_default() {
+                f(c)
+            },
         }
     }
     fn escape_str(s: &str) -> String {
@@ -613,29 +618,42 @@ pub enum RenderOption {
 }
 
 /// Returns vec holding all the default render options.
-pub fn default_options() -> Vec<RenderOption> { vec![] }
+pub fn default_options() -> Vec<RenderOption> {
+    vec![]
+}
 
 /// Renders directed graph `g` into the writer `w` in DOT syntax.
 /// (Simple wrapper around `render_opts` that passes a default set of options.)
-pub fn render<'a, N:Clone+'a, E:Clone+'a, G:Labeller<'a,N,E>+GraphWalk<'a,N,E>, W:Write>(
-              g: &'a G,
-              w: &mut W) -> io::Result<()> {
+pub fn render<'a,
+              N: Clone + 'a,
+              E: Clone + 'a,
+              G: Labeller<'a, N, E> + GraphWalk<'a, N, E>,
+              W: Write>
+    (g: &'a G,
+     w: &mut W)
+     -> io::Result<()> {
     render_opts(g, w, &[])
 }
 
 /// Renders directed graph `g` into the writer `w` in DOT syntax.
 /// (Main entry point for the library.)
-pub fn render_opts<'a, N:Clone+'a, E:Clone+'a, G:Labeller<'a,N,E>+GraphWalk<'a,N,E>, W:Write>(
-              g: &'a G,
-              w: &mut W,
-              options: &[RenderOption]) -> io::Result<()>
-{
-    fn writeln<W:Write>(w: &mut W, arg: &[&str]) -> io::Result<()> {
-        for &s in arg { try!(w.write_all(s.as_bytes())); }
+pub fn render_opts<'a,
+                   N: Clone + 'a,
+                   E: Clone + 'a,
+                   G: Labeller<'a, N, E> + GraphWalk<'a, N, E>,
+                   W: Write>
+    (g: &'a G,
+     w: &mut W,
+     options: &[RenderOption])
+     -> io::Result<()> {
+    fn writeln<W: Write>(w: &mut W, arg: &[&str]) -> io::Result<()> {
+        for &s in arg {
+            try!(w.write_all(s.as_bytes()));
+        }
         write!(w, "\n")
     }
 
-    fn indent<W:Write>(w: &mut W) -> io::Result<()> {
+    fn indent<W: Write>(w: &mut W) -> io::Result<()> {
         w.write_all(b"    ")
     }
 
@@ -748,7 +766,7 @@ struct LabelledGraph {
     // A simple wrapper around LabelledGraph that forces the labels to
     // be emitted as EscStr.
     struct LabelledGraphWithEscStrs {
-        graph: LabelledGraph
+        graph: LabelledGraph,
     }
 
     enum NodeLabels<L> {
@@ -762,13 +780,10 @@ enum NodeLabels<L> {
     impl NodeLabels<&'static str> {
         fn to_opt_strs(self) -> Vec<Option<&'static str>> {
             match self {
-                UnlabelledNodes(len)
-                    => vec![None; len],
-                AllNodesLabelled(lbls)
-                    => lbls.into_iter().map(
+                UnlabelledNodes(len) => vec![None; len],
+                AllNodesLabelled(lbls) => lbls.into_iter().map(
                         |l|Some(l)).collect(),
-                SomeNodesLabelled(lbls)
-                    => lbls.into_iter().collect(),
+                SomeNodesLabelled(lbls) => lbls.into_iter().collect(),
             }
         }
 
@@ -785,7 +800,8 @@ impl LabelledGraph {
         fn new(name: &'static str,
                node_labels: Trivial,
                edges: Vec<Edge>,
-               node_styles: Option<Vec<Style>>) -> LabelledGraph {
+               node_styles: Option<Vec<Style>>)
+               -> LabelledGraph {
             let count = node_labels.len();
             LabelledGraph {
                 name: name,
@@ -794,7 +810,7 @@ fn new(name: &'static str,
                 node_styles: match node_styles {
                     Some(nodes) => nodes,
                     None => vec![Style::None; count],
-                }
+                },
             }
         }
     }
@@ -802,13 +818,9 @@ fn new(name: &'static str,
     impl LabelledGraphWithEscStrs {
         fn new(name: &'static str,
                node_labels: Trivial,
-               edges: Vec<Edge>) -> LabelledGraphWithEscStrs {
-            LabelledGraphWithEscStrs {
-                graph: LabelledGraph::new(name,
-                                          node_labels,
-                                          edges,
-                                          None)
-            }
+               edges: Vec<Edge>)
+               -> LabelledGraphWithEscStrs {
+            LabelledGraphWithEscStrs { graph: LabelledGraph::new(name, node_labels, edges, None) }
         }
     }
 
@@ -826,29 +838,33 @@ fn node_id(&'a self, n: &Node) -> Id<'a> {
         fn node_label(&'a self, n: &Node) -> LabelText<'a> {
             match self.node_labels[*n] {
                 Some(ref l) => LabelStr(l.into_cow()),
-                None        => LabelStr(id_name(n).name()),
+                None => LabelStr(id_name(n).name()),
             }
         }
-        fn edge_label(&'a self, e: & &'a Edge) -> LabelText<'a> {
+        fn edge_label(&'a self, e: &&'a Edge) -> LabelText<'a> {
             LabelStr(e.label.into_cow())
         }
         fn node_style(&'a self, n: &Node) -> Style {
             self.node_styles[*n]
         }
-        fn edge_style(&'a self, e: & &'a Edge) -> Style {
+        fn edge_style(&'a self, e: &&'a Edge) -> Style {
             e.style
         }
     }
 
     impl<'a> Labeller<'a, Node, &'a Edge> for LabelledGraphWithEscStrs {
-        fn graph_id(&'a self) -> Id<'a> { self.graph.graph_id() }
-        fn node_id(&'a self, n: &Node) -> Id<'a> { self.graph.node_id(n) }
+        fn graph_id(&'a self) -> Id<'a> {
+            self.graph.graph_id()
+        }
+        fn node_id(&'a self, n: &Node) -> Id<'a> {
+            self.graph.node_id(n)
+        }
         fn node_label(&'a self, n: &Node) -> LabelText<'a> {
             match self.graph.node_label(n) {
                 LabelStr(s) | EscStr(s) | HtmlStr(s) => EscStr(s),
             }
         }
-        fn edge_label(&'a self, e: & &'a Edge) -> LabelText<'a> {
+        fn edge_label(&'a self, e: &&'a Edge) -> LabelText<'a> {
             match self.graph.edge_label(e) {
                 LabelStr(s) | EscStr(s) | HtmlStr(s) => EscStr(s),
             }
@@ -856,31 +872,31 @@ fn edge_label(&'a self, e: & &'a Edge) -> LabelText<'a> {
     }
 
     impl<'a> GraphWalk<'a, Node, &'a Edge> for LabelledGraph {
-        fn nodes(&'a self) -> Nodes<'a,Node> {
+        fn nodes(&'a self) -> Nodes<'a, Node> {
             (0..self.node_labels.len()).collect()
         }
-        fn edges(&'a self) -> Edges<'a,&'a Edge> {
+        fn edges(&'a self) -> Edges<'a, &'a Edge> {
             self.edges.iter().collect()
         }
-        fn source(&'a self, edge: & &'a Edge) -> Node {
+        fn source(&'a self, edge: &&'a Edge) -> Node {
             edge.from
         }
-        fn target(&'a self, edge: & &'a Edge) -> Node {
+        fn target(&'a self, edge: &&'a Edge) -> Node {
             edge.to
         }
     }
 
     impl<'a> GraphWalk<'a, Node, &'a Edge> for LabelledGraphWithEscStrs {
-        fn nodes(&'a self) -> Nodes<'a,Node> {
+        fn nodes(&'a self) -> Nodes<'a, Node> {
             self.graph.nodes()
         }
-        fn edges(&'a self) -> Edges<'a,&'a Edge> {
+        fn edges(&'a self) -> Edges<'a, &'a Edge> {
             self.graph.edges()
         }
-        fn source(&'a self, edge: & &'a Edge) -> Node {
+        fn source(&'a self, edge: &&'a Edge) -> Node {
             edge.from
         }
-        fn target(&'a self, edge: & &'a Edge) -> Node {
+        fn target(&'a self, edge: &&'a Edge) -> Node {
             edge.to
         }
     }
@@ -899,7 +915,7 @@ fn test_input(g: LabelledGraph) -> io::Result<String> {
 
     #[test]
     fn empty_graph() {
-        let labels : Trivial = UnlabelledNodes(0);
+        let labels: Trivial = UnlabelledNodes(0);
         let r = test_input(LabelledGraph::new("empty_graph", labels, vec![], None));
         assert_eq!(r.unwrap(),
 r#"digraph empty_graph {
@@ -909,7 +925,7 @@ fn empty_graph() {
 
     #[test]
     fn single_node() {
-        let labels : Trivial = UnlabelledNodes(1);
+        let labels: Trivial = UnlabelledNodes(1);
         let r = test_input(LabelledGraph::new("single_node", labels, vec![], None));
         assert_eq!(r.unwrap(),
 r#"digraph single_node {
@@ -920,7 +936,7 @@ fn single_node() {
 
     #[test]
     fn single_node_with_style() {
-        let labels : Trivial = UnlabelledNodes(1);
+        let labels: Trivial = UnlabelledNodes(1);
         let styles = Some(vec![Style::Dashed]);
         let r = test_input(LabelledGraph::new("single_node", labels, vec![], styles));
         assert_eq!(r.unwrap(),
@@ -932,9 +948,11 @@ fn single_node_with_style() {
 
     #[test]
     fn single_edge() {
-        let labels : Trivial = UnlabelledNodes(2);
-        let result = test_input(LabelledGraph::new("single_edge", labels,
-                                                   vec![edge(0, 1, "E", Style::None)], None));
+        let labels: Trivial = UnlabelledNodes(2);
+        let result = test_input(LabelledGraph::new("single_edge",
+                                                   labels,
+                                                   vec![edge(0, 1, "E", Style::None)],
+                                                   None));
         assert_eq!(result.unwrap(),
 r#"digraph single_edge {
     N0[label="N0"];
@@ -946,9 +964,11 @@ fn single_edge() {
 
     #[test]
     fn single_edge_with_style() {
-        let labels : Trivial = UnlabelledNodes(2);
-        let result = test_input(LabelledGraph::new("single_edge", labels,
-                                                   vec![edge(0, 1, "E", Style::Bold)], None));
+        let labels: Trivial = UnlabelledNodes(2);
+        let result = test_input(LabelledGraph::new("single_edge",
+                                                   labels,
+                                                   vec![edge(0, 1, "E", Style::Bold)],
+                                                   None));
         assert_eq!(result.unwrap(),
 r#"digraph single_edge {
     N0[label="N0"];
@@ -960,10 +980,12 @@ fn single_edge_with_style() {
 
     #[test]
     fn test_some_labelled() {
-        let labels : Trivial = SomeNodesLabelled(vec![Some("A"), None]);
+        let labels: Trivial = SomeNodesLabelled(vec![Some("A"), None]);
         let styles = Some(vec![Style::None, Style::Dotted]);
-        let result = test_input(LabelledGraph::new("test_some_labelled", labels,
-                                                   vec![edge(0, 1, "A-1", Style::None)], styles));
+        let result = test_input(LabelledGraph::new("test_some_labelled",
+                                                   labels,
+                                                   vec![edge(0, 1, "A-1", Style::None)],
+                                                   styles));
         assert_eq!(result.unwrap(),
 r#"digraph test_some_labelled {
     N0[label="A"];
@@ -975,9 +997,11 @@ fn test_some_labelled() {
 
     #[test]
     fn single_cyclic_node() {
-        let labels : Trivial = UnlabelledNodes(1);
-        let r = test_input(LabelledGraph::new("single_cyclic_node", labels,
-                                              vec![edge(0, 0, "E", Style::None)], None));
+        let labels: Trivial = UnlabelledNodes(1);
+        let r = test_input(LabelledGraph::new("single_cyclic_node",
+                                              labels,
+                                              vec![edge(0, 0, "E", Style::None)],
+                                              None));
         assert_eq!(r.unwrap(),
 r#"digraph single_cyclic_node {
     N0[label="N0"];
@@ -989,11 +1013,11 @@ fn single_cyclic_node() {
     #[test]
     fn hasse_diagram() {
         let labels = AllNodesLabelled(vec!("{x,y}", "{x}", "{y}", "{}"));
-        let r = test_input(LabelledGraph::new(
-            "hasse_diagram", labels,
-            vec![edge(0, 1, "", Style::None), edge(0, 2, "", Style::None),
+        let r = test_input(LabelledGraph::new("hasse_diagram",
+                                              labels,
+                                              vec![edge(0, 1, "", Style::None), edge(0, 2, "", Style::None),
                  edge(1, 3, "", Style::None), edge(2, 3, "", Style::None)],
-            None));
+                                              None));
         assert_eq!(r.unwrap(),
 r#"digraph hasse_diagram {
     N0[label="{x,y}"];
@@ -1024,9 +1048,9 @@ fn left_aligned_text() {
 
         let mut writer = Vec::new();
 
-        let g = LabelledGraphWithEscStrs::new(
-            "syntax_tree", labels,
-            vec![edge(0, 1, "then", Style::None), edge(0, 2, "else", Style::None),
+        let g = LabelledGraphWithEscStrs::new("syntax_tree",
+                                              labels,
+                                              vec![edge(0, 1, "then", Style::None), edge(0, 2, "else", Style::None),
                  edge(1, 3, ";", Style::None),    edge(2, 3, ";", Style::None)]);
 
         render(&g, &mut writer).unwrap();
@@ -1051,8 +1075,9 @@ fn left_aligned_text() {
     fn simple_id_construction() {
         let id1 = Id::new("hello");
         match id1 {
-            Ok(_) => {;},
-            Err(..) => panic!("'hello' is not a valid value for id anymore")
+            Ok(_) => {;
+            }
+            Err(..) => panic!("'hello' is not a valid value for id anymore"),
         }
     }
 
@@ -1061,7 +1086,8 @@ fn badly_formatted_id() {
         let id2 = Id::new("Weird { struct : ure } !!!");
         match id2 {
             Ok(_) => panic!("graphviz id suddenly allows spaces, brackets and stuff"),
-            Err(..) => {;}
+            Err(..) => {;
+            }
         }
     }
 }