Skip to content
Myr

grep-searcher: add Box<...> impl for Sink

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by Andrew Gallant · committed by Andrew Gallant · parent 3b5cdea · Browse files · 1 file+47 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+47 added−0 removed

  • other:+47 added−0 removed

1 file+47 added−0 removed

modified:grep-searcher/src/sink.rs+47 added
244 unmodified lines
245 (**self).finish(searcher, sink_finish)246 }247}248249impl<S: Sink + ?Sized> Sink for Box<S> {250 type Error = S::Error;251252 #[inline]253 fn matched(254 &mut self,255 searcher: &Searcher,256 mat: &SinkMatch,257 ) -> Result<bool, S::Error> {258 (**self).matched(searcher, mat)259 }260261 #[inline]262 fn context(263 &mut self,264 searcher: &Searcher,265 context: &SinkContext,266 ) -> Result<bool, S::Error> {267 (**self).context(searcher, context)268 }269270 #[inline]271 fn context_break(272 &mut self,273 searcher: &Searcher,274 ) -> Result<bool, S::Error> {275 (**self).context_break(searcher)276 }277278 #[inline]279 fn begin(280 &mut self,281 searcher: &Searcher,282 ) -> Result<bool, S::Error> {283 (**self).begin(searcher)284 }285286 #[inline]287 fn finish(288 &mut self,289 searcher: &Searcher,290 sink_finish: &SinkFinish,291 ) -> Result<(), S::Error> {292 (**self).finish(searcher, sink_finish)293 }294}295296/// Summary data reported at the end of a search.297///298/// This reports data such as the total number of bytes searched and the299/// absolute offset of the first occurrence of binary data, if any were found.
307 unmodified lines