mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2024-12-07 11:13:17 +02:00
grep-searcher: add Box<...> impl for Sink
We initially did not have this impl because the first revision of the Sink trait was much more complicated. In particular, each method was parameterized over a Matcher. But not every Sink impl actually needs a Matcher, and it is just as easy to borrow a Matcher explicitly, so the added parameterization wasn't holding its own. This does permit Sink implementations to be used as trait objects. One key use case here is to reduce compile times, since there is quite a bit of code inside grep-searcher that is parameterized on Sink. Unfortunately, that code is *also* parameterized on Matcher, and the various printers in grep-printer are also parameterized on Matcher, which means Sink trait objects are necessary but no sufficient for a major reduction in compile times. Unfortunately, the path to making Matcher object safe isn't quite clear. Extension traits maybe? There's also stuff in the Serde ecosystem that might help, but the type shenanigans can get pretty gnarly.
This commit is contained in:
parent
3b5cdea862
commit
3dd4b77dfb
@ -246,6 +246,53 @@ impl<'a, S: Sink> Sink for &'a mut S {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Sink + ?Sized> Sink for Box<S> {
|
||||
type Error = S::Error;
|
||||
|
||||
#[inline]
|
||||
fn matched(
|
||||
&mut self,
|
||||
searcher: &Searcher,
|
||||
mat: &SinkMatch,
|
||||
) -> Result<bool, S::Error> {
|
||||
(**self).matched(searcher, mat)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn context(
|
||||
&mut self,
|
||||
searcher: &Searcher,
|
||||
context: &SinkContext,
|
||||
) -> Result<bool, S::Error> {
|
||||
(**self).context(searcher, context)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn context_break(
|
||||
&mut self,
|
||||
searcher: &Searcher,
|
||||
) -> Result<bool, S::Error> {
|
||||
(**self).context_break(searcher)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn begin(
|
||||
&mut self,
|
||||
searcher: &Searcher,
|
||||
) -> Result<bool, S::Error> {
|
||||
(**self).begin(searcher)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn finish(
|
||||
&mut self,
|
||||
searcher: &Searcher,
|
||||
sink_finish: &SinkFinish,
|
||||
) -> Result<(), S::Error> {
|
||||
(**self).finish(searcher, sink_finish)
|
||||
}
|
||||
}
|
||||
|
||||
/// Summary data reported at the end of a search.
|
||||
///
|
||||
/// This reports data such as the total number of bytes searched and the
|
||||
|
Loading…
Reference in New Issue
Block a user