about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNick Cameron <ncameron@mozilla.com>2018-06-28 11:50:03 +1200
committerNick Cameron <ncameron@mozilla.com>2018-07-12 21:37:28 +1200
commitb6ea973d19ff1063ff97a95666e988bae226ebb2 (patch)
tree0f5cae82b4576b392ce546a5356d648887b42dcc
parentfba6b68bf2eee8c47da423a7e1204486eb77b489 (diff)
Factor out PairParts::infix
-rw-r--r--src/expr.rs19
-rw-r--r--src/patterns.rs2
2 files changed, 16 insertions, 5 deletions
diff --git a/src/expr.rs b/src/expr.rs
index 6928b77f360..d9fa4717357 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -92,7 +92,7 @@ pub fn format_expr(
                 rewrite_pair(
                     &**lhs,
                     &**rhs,
-                    PairParts::new("", &format!(" {} ", context.snippet(op.span)), ""),
+                    PairParts::infix(&format!(" {} ", context.snippet(op.span))),
                     context,
                     shape,
                     context.config.binop_separator(),
@@ -211,7 +211,7 @@ pub fn format_expr(
         ast::ExprKind::Cast(ref expr, ref ty) => rewrite_pair(
             &**expr,
             &**ty,
-            PairParts::new("", " as ", ""),
+            PairParts::infix(" as "),
             context,
             shape,
             SeparatorPlace::Front,
@@ -219,7 +219,7 @@ pub fn format_expr(
         ast::ExprKind::Type(ref expr, ref ty) => rewrite_pair(
             &**expr,
             &**ty,
-            PairParts::new("", ": ", ""),
+            PairParts::infix(": "),
             context,
             shape,
             SeparatorPlace::Back,
@@ -288,7 +288,7 @@ pub fn format_expr(
                     rewrite_pair(
                         &*lhs,
                         &*rhs,
-                        PairParts::new("", &sp_delim, ""),
+                        PairParts::infix(&sp_delim),
                         context,
                         shape,
                         context.config.binop_separator(),
@@ -435,6 +435,7 @@ fn rewrite_simple_binaries(
     None
 }
 
+/// Sigils that decorate a binop pair.
 #[derive(new, Clone, Copy)]
 pub struct PairParts<'a> {
     prefix: &'a str,
@@ -442,6 +443,16 @@ pub struct PairParts<'a> {
     suffix: &'a str,
 }
 
+impl<'a> PairParts<'a> {
+    pub fn infix(infix: &'a str) -> PairParts<'a> {
+        PairParts {
+            prefix: "",
+            infix,
+            suffix: "",
+        }
+    }
+}
+
 pub fn rewrite_pair<LHS, RHS>(
     lhs: &LHS,
     rhs: &RHS,
diff --git a/src/patterns.rs b/src/patterns.rs
index 85b9b84b6b2..5e3cbfc31f3 100644
--- a/src/patterns.rs
+++ b/src/patterns.rs
@@ -112,7 +112,7 @@ impl Rewrite for Pat {
                 rewrite_pair(
                     &**lhs,
                     &**rhs,
-                    PairParts::new("", &infix, ""),
+                    PairParts::infix(&infix),
                     context,
                     shape,
                     SeparatorPlace::Front,