Print an indented block delimited by `before` and `after`, with body written by `f`.
(&mut self, before: &str, f: impl FnOnce(&mut Self) -> Res, after: &str)
| 66 | |
| 67 | /// Print an indented block delimited by `before` and `after`, with body written by `f`. |
| 68 | pub fn delimited_block<Res>(&mut self, before: &str, f: impl FnOnce(&mut Self) -> Res, after: &str) -> Res { |
| 69 | self.writer.write_str(before).unwrap(); |
| 70 | let res = self.with_indent(|out| { |
| 71 | out.newline(); |
| 72 | // Need an explicit `write_indent` call here because calling `out.newline` |
| 73 | // will not cause the subsequent line to be indented, as `write_str` thinks |
| 74 | // it's an empty line. |
| 75 | out.write_indent().unwrap(); |
| 76 | f(out) |
| 77 | }); |
| 78 | self.writer.write_str(after).unwrap(); |
| 79 | res |
| 80 | } |
| 81 | } |
| 82 | impl<W: fmt::Write> fmt::Write for CodeIndenter<W> { |
| 83 | fn write_str(&mut self, s: &str) -> fmt::Result { |
no test coverage detected