]> git.lizzy.rs Git - rust.git/commitdiff
Implement rhs_overhead method against Shape
authorSeiichi Uchida <seuchida@gmail.com>
Sun, 9 Jul 2017 17:16:57 +0000 (02:16 +0900)
committerSeiichi Uchida <seuchida@gmail.com>
Sun, 9 Jul 2017 17:16:57 +0000 (02:16 +0900)
src/expr.rs
src/lib.rs

index 971bdc21aaa90748286fcda23a972670bb8634fd..4b4596e59d7f8dc6781bd18eb03e63ae55a63dfe 100644 (file)
@@ -419,11 +419,7 @@ pub fn rewrite_pair<LHS, RHS>(
         }
         Style::Rfc => {
             // Try to calculate the initial constraint on the right hand side.
-            let rhs_overhead = context
-                .config
-                .max_width()
-                .checked_sub(shape.used_width() + shape.width)
-                .unwrap_or(0);
+            let rhs_overhead = shape.rhs_overhead(context.config);
             try_opt!(
                 Shape::indented(shape.indent.block_indent(context.config), context.config)
                     .sub_width(rhs_overhead)
@@ -2543,12 +2539,8 @@ fn rewrite_index(
     }
 
     // Try putting index on the next line and see if it fits in a single line.
-    let indent = shape.indent.block_indent(&context.config);
-    let rhs_overhead = context
-        .config
-        .max_width()
-        .checked_sub(shape.used_width() + shape.width)
-        .unwrap_or(0);
+    let indent = shape.indent.block_indent(context.config);
+    let rhs_overhead = shape.rhs_overhead(context.config);
     let index_shape = try_opt!(Shape::indented(indent, context.config).offset_left(lbr.len()));
     let index_shape = try_opt!(index_shape.sub_width(rbr.len() + rhs_overhead));
     let new_index_rw = index.rewrite(context, index_shape);
index f0c3ebf49a1d0248b9d3b1cd17ec75efc3fa0acd..b27a02a17a905ead7c012d8238bd1ac66ee9e0da 100644 (file)
@@ -363,6 +363,13 @@ pub fn offset_left(&self, width: usize) -> Option<Shape> {
     pub fn used_width(&self) -> usize {
         self.indent.block_indent + self.offset
     }
+
+    pub fn rhs_overhead(&self, config: &Config) -> usize {
+        config
+            .max_width()
+            .checked_sub(self.used_width() + self.width)
+            .unwrap_or(0)
+    }
 }
 
 pub enum ErrorKind {