]> git.lizzy.rs Git - rust.git/commitdiff
Implement StringFormat::new()
authortopecongiro <seuchida@gmail.com>
Sun, 1 Oct 2017 10:39:00 +0000 (19:39 +0900)
committertopecongiro <seuchida@gmail.com>
Sun, 1 Oct 2017 10:39:00 +0000 (19:39 +0900)
src/expr.rs
src/string.rs

index c240ecdda53649c4431e6f18fcfa42c82237c751..c7a71cde69b292db8e3bf5dae2fac25735074418 100644 (file)
@@ -1976,20 +1976,10 @@ fn rewrite_string_lit(context: &RewriteContext, span: Span, shape: Shape) -> Opt
         return Some(string_lit);
     }
 
-    let fmt = StringFormat {
-        opener: "\"",
-        closer: "\"",
-        line_start: " ",
-        line_end: "\\",
-        shape: shape,
-        trim_end: false,
-        config: context.config,
-    };
-
     // Remove the quote characters.
     let str_lit = &string_lit[1..string_lit.len() - 1];
 
-    rewrite_string(str_lit, &fmt)
+    rewrite_string(str_lit, &StringFormat::new(shape, context.config))
 }
 
 fn string_requires_rewrite(
index 8090926522dbd9022b72e467aac11bb93a6bab04..efec7ff23778254ed2851421100a910ffff3aa44 100644 (file)
@@ -29,6 +29,20 @@ pub struct StringFormat<'a> {
     pub config: &'a Config,
 }
 
+impl<'a> StringFormat<'a> {
+    pub fn new(shape: Shape, config: &'a Config) -> StringFormat<'a> {
+        StringFormat {
+            opener: "\"",
+            closer: "\"",
+            line_start: " ",
+            line_end: "\\",
+            shape: shape,
+            trim_end: false,
+            config: config,
+        }
+    }
+}
+
 // FIXME: simplify this!
 pub fn rewrite_string<'a>(orig: &str, fmt: &StringFormat<'a>) -> Option<String> {
     // Strip line breaks.
@@ -133,16 +147,7 @@ mod test {
     #[test]
     fn issue343() {
         let config = Default::default();
-        let fmt = StringFormat {
-            opener: "\"",
-            closer: "\"",
-            line_start: " ",
-            line_end: "\\",
-            shape: Shape::legacy(2, Indent::empty()),
-            trim_end: false,
-            config: &config,
-        };
-
+        let fmt = StringFormat::new(Shape::legacy(2, Indent::empty()), &config);
         rewrite_string("eq_", &fmt);
     }
 }