printer: clean-up
Like a previous commit did for the grep-cli crate, this does some polishing to the grep-printer crate. We aren't able to achieve as much as we did with grep-cli, but we at least eliminate all rust-analyzer lints and group imports in the way I've been doing recently. Next we'll start doing some more invasive changes.
This commit is contained in:
@@ -27,11 +27,11 @@ contain matches.
|
||||
This example shows how to create a "standard" printer and execute a search.
|
||||
|
||||
```
|
||||
use std::error::Error;
|
||||
|
||||
use grep_regex::RegexMatcher;
|
||||
use grep_printer::Standard;
|
||||
use grep_searcher::Searcher;
|
||||
use {
|
||||
grep_regex::RegexMatcher,
|
||||
grep_printer::Standard,
|
||||
grep_searcher::Searcher,
|
||||
};
|
||||
|
||||
const SHERLOCK: &'static [u8] = b"\
|
||||
For the Doctor Watsons of this world, as opposed to the Sherlock
|
||||
@@ -42,41 +42,40 @@ but Doctor Watson has to have it taken out for him and dusted,
|
||||
and exhibited clearly, with a label attached.
|
||||
";
|
||||
|
||||
# fn main() { example().unwrap(); }
|
||||
fn example() -> Result<(), Box<Error>> {
|
||||
let matcher = RegexMatcher::new(r"Sherlock")?;
|
||||
let mut printer = Standard::new_no_color(vec![]);
|
||||
Searcher::new().search_slice(&matcher, SHERLOCK, printer.sink(&matcher))?;
|
||||
let matcher = RegexMatcher::new(r"Sherlock")?;
|
||||
let mut printer = Standard::new_no_color(vec![]);
|
||||
Searcher::new().search_slice(&matcher, SHERLOCK, printer.sink(&matcher))?;
|
||||
|
||||
// into_inner gives us back the underlying writer we provided to
|
||||
// new_no_color, which is wrapped in a termcolor::NoColor. Thus, a second
|
||||
// into_inner gives us back the actual buffer.
|
||||
let output = String::from_utf8(printer.into_inner().into_inner())?;
|
||||
let expected = "\
|
||||
// into_inner gives us back the underlying writer we provided to
|
||||
// new_no_color, which is wrapped in a termcolor::NoColor. Thus, a second
|
||||
// into_inner gives us back the actual buffer.
|
||||
let output = String::from_utf8(printer.into_inner().into_inner())?;
|
||||
let expected = "\
|
||||
1:For the Doctor Watsons of this world, as opposed to the Sherlock
|
||||
3:be, to a very large extent, the result of luck. Sherlock Holmes
|
||||
";
|
||||
assert_eq!(output, expected);
|
||||
Ok(())
|
||||
}
|
||||
assert_eq!(output, expected);
|
||||
# Ok::<(), Box<dyn std::error::Error>>(())
|
||||
```
|
||||
*/
|
||||
|
||||
#![deny(missing_docs)]
|
||||
#![cfg_attr(feature = "pattern", feature(pattern))]
|
||||
|
||||
pub use crate::color::{
|
||||
default_color_specs, ColorError, ColorSpecs, UserColorSpec,
|
||||
pub use crate::{
|
||||
color::{default_color_specs, ColorError, ColorSpecs, UserColorSpec},
|
||||
hyperlink::{
|
||||
HyperlinkPath, HyperlinkPattern, HyperlinkPatternBuilder,
|
||||
HyperlinkPatternError, HyperlinkSpan, HyperlinkValues,
|
||||
},
|
||||
standard::{Standard, StandardBuilder, StandardSink},
|
||||
stats::Stats,
|
||||
summary::{Summary, SummaryBuilder, SummaryKind, SummarySink},
|
||||
util::PrinterPath,
|
||||
};
|
||||
pub use crate::hyperlink::{
|
||||
HyperlinkPath, HyperlinkPattern, HyperlinkPatternError, HyperlinkSpan,
|
||||
HyperlinkValues,
|
||||
};
|
||||
#[cfg(feature = "serde1")]
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
pub use crate::json::{JSONBuilder, JSONSink, JSON};
|
||||
pub use crate::standard::{Standard, StandardBuilder, StandardSink};
|
||||
pub use crate::stats::Stats;
|
||||
pub use crate::summary::{Summary, SummaryBuilder, SummaryKind, SummarySink};
|
||||
pub use crate::util::PrinterPath;
|
||||
|
||||
// The maximum number of bytes to execute a search to account for look-ahead.
|
||||
//
|
||||
@@ -96,9 +95,9 @@ mod color;
|
||||
mod counter;
|
||||
mod hyperlink;
|
||||
mod hyperlink_aliases;
|
||||
#[cfg(feature = "serde1")]
|
||||
#[cfg(feature = "serde")]
|
||||
mod json;
|
||||
#[cfg(feature = "serde1")]
|
||||
#[cfg(feature = "serde")]
|
||||
mod jsont;
|
||||
mod standard;
|
||||
mod stats;
|
||||
|
||||
Reference in New Issue
Block a user