]> git.lizzy.rs Git - rust.git/blobdiff - src/shape.rs
Fixup formatting
[rust.git] / src / shape.rs
index ab33826c028f9ca28209cf8cff240fd90ee185ba..5868f0b85fdff2b1c89ce79219e0c55aa152defe 100644 (file)
@@ -91,7 +91,7 @@ fn to_string_inner(&self, config: &Config, offset: usize) -> Cow<'static, str> {
         };
         let num_chars = num_tabs + num_spaces;
         if num_tabs == 0 && num_chars + offset <= INDENT_BUFFER_LEN {
-            Cow::from(&INDENT_BUFFER[offset..num_chars + 1])
+            Cow::from(&INDENT_BUFFER[offset..=num_chars])
         } else {
             let mut indent = String::with_capacity(num_chars + if offset == 0 { 1 } else { 0 });
             if offset == 0 {
@@ -274,6 +274,12 @@ pub fn comment(&self, config: &Config) -> Shape {
         );
         Shape { width, ..*self }
     }
+
+    pub fn to_string_with_newline(&self, config: &Config) -> Cow<'static, str> {
+        let mut offset_indent = self.indent;
+        offset_indent.alignment = self.offset;
+        offset_indent.to_string_inner(config, 0)
+    }
 }
 
 #[cfg(test)]