mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-28 23:32:41 +00:00
a061ac022e
There's a risk of forgetting to call `remove_label()` and I've wanted to reduce that risk for a long time. I considered creating RAII adapters that implement `Drop`, but I didn't like that that would ignore errors (such as `BrokenPipe`) that can happen while emitting an escape sequence in `remove_label()`. I would ideally have liked Python's context managers here, but Rust doesn't have that. Instead, we get to use closures. That works pretty well, except that we can't return other errors than `io::Error` inside the closures. Even with that limitation, we can use the new `with_label()` method in all but a few cases. We can't define the `with_label()` method directly in the trait because `&mut self` is not a trait object, so we can't pass it on to the closure (which expects a trait object). The solution is to use `impl dyn Formatter` (thanks to @kupiakos for figuring that out!). That unfortunately means that we can *only* call the function on trait objects, so if `f` is a concrete formatter type (e.g. `PlainTextFormatter`), then `f.with_label()` won't compile. Since we only ever access the formatters as trait objects, that's not really a problem, however. |
||
---|---|---|
.. | ||
cli_util.rs | ||
commands.rs | ||
config.rs | ||
diff_edit.rs | ||
formatter.rs | ||
graphlog.rs | ||
lib.rs | ||
main.rs | ||
template.pest | ||
template_parser.rs | ||
templater.rs | ||
ui.rs |