The previous big match statement did three separate things in the
same deeply indented code block:
Prepare the buffer
Identify the content to paste
Paste the proper content
Preparing the buffer was simplified by just calling
ensure_trailing_newline beforehand, as that's essentially what
the special cases deep inside the match statement were doing
anyway. This is done indiscriminately due to the borrow checker,
which wouldn't like us manipulating the buffer to add a newline
while we held an immutable reference to it in buffer. This has
the unfortunate-ish side effect of requiring modifications to the
tests to account for the fact that a trailing newline is added.
Separating 2 and 3 allows us to refocus the match statement on
identification, and, if there is content, we can paste later down
the function.
1 and 2 are still homogeneous in the match statement, which isn't
super pretty, but, as they both depend on the same data (and
conditionals thereof), it's not too big a deal.
Just shortening a match statement!
Commit message below:
The previous big match statement did three separate things in the same deeply indented code block:
Preparing the buffer was simplified by just calling
ensure_trailing_newline
beforehand, as that's essentially what the special cases deep inside the match statement were doing anyway. This is done indiscriminately due to the borrow checker, which wouldn't like us manipulating the buffer to add a newline while we held an immutable reference to it inbuffer
. This has the unfortunate-ish side effect of requiring modifications to the tests to account for the fact that a trailing newline is added.Separating 2 and 3 allows us to refocus the match statement on identification, and, if there is content, we can paste later down the function.
1 and 2 are still homogeneous in the match statement, which isn't super pretty, but, as they both depend on the same data (and conditionals thereof), it's not too big a deal.