]> git.lizzy.rs Git - rust.git/commitdiff
Refactor Shape
authortopecongiro <seuchida@gmail.com>
Sun, 7 May 2017 22:24:32 +0000 (07:24 +0900)
committertopecongiro <seuchida@gmail.com>
Sun, 7 May 2017 22:24:32 +0000 (07:24 +0900)
src/lib.rs
src/visitor.rs

index cd90f5fe931a842567d6f8acdd88d0248f4f3904..13b2df0674059d78834d17ac9ac4f817df223d45 100644 (file)
@@ -298,34 +298,27 @@ pub fn block_indent(&self, extra_width: usize) -> Shape {
     }
 
     pub fn block_left(&self, width: usize) -> Option<Shape> {
-        let block_shape = self.block_indent(width);
-        Some(Shape {
-                 width: try_opt!(block_shape.width.checked_sub(width)),
-                 ..block_shape
-             })
+        self.block_indent(width).sub_width(width)
     }
 
     pub fn add_offset(&self, extra_width: usize) -> Shape {
         Shape {
-            width: self.width,
-            indent: self.indent,
             offset: self.offset + extra_width,
+            ..*self
         }
     }
 
     pub fn block(&self) -> Shape {
         Shape {
-            width: self.width,
             indent: self.indent.block_only(),
-            offset: self.offset,
+            ..*self
         }
     }
 
     pub fn sub_width(&self, width: usize) -> Option<Shape> {
         Some(Shape {
                  width: try_opt!(self.width.checked_sub(width)),
-                 indent: self.indent,
-                 offset: self.offset,
+                 ..*self
              })
     }
 
@@ -338,11 +331,7 @@ pub fn shrink_left(&self, width: usize) -> Option<Shape> {
     }
 
     pub fn offset_left(&self, width: usize) -> Option<Shape> {
-        Some(Shape {
-                 width: try_opt!(self.width.checked_sub(width)),
-                 indent: self.indent,
-                 offset: self.offset + width,
-             })
+        self.add_offset(width).sub_width(width)
     }
 
     pub fn used_width(&self) -> usize {
index 48e65abb6a810470bb8a1281a1a795faf4b0542b..38185047b7e0140a0500e84ad11c0ec2dfb489d2 100644 (file)
@@ -455,10 +455,7 @@ pub fn from_codemap(parse_session: &'a ParseSess, config: &'a Config) -> FmtVisi
             codemap: parse_session.codemap(),
             buffer: StringBuffer::new(),
             last_pos: BytePos(0),
-            block_indent: Indent {
-                block_indent: 0,
-                alignment: 0,
-            },
+            block_indent: Indent::empty(),
             config: config,
             failed: false,
         }