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:
@@ -5,32 +5,32 @@ use termcolor::{ColorSpec, HyperlinkSpec, WriteColor};
|
||||
/// A writer that counts the number of bytes that have been successfully
|
||||
/// written.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CounterWriter<W> {
|
||||
pub(crate) struct CounterWriter<W> {
|
||||
wtr: W,
|
||||
count: u64,
|
||||
total_count: u64,
|
||||
}
|
||||
|
||||
impl<W: Write> CounterWriter<W> {
|
||||
pub fn new(wtr: W) -> CounterWriter<W> {
|
||||
CounterWriter { wtr: wtr, count: 0, total_count: 0 }
|
||||
pub(crate) fn new(wtr: W) -> CounterWriter<W> {
|
||||
CounterWriter { wtr, count: 0, total_count: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
impl<W> CounterWriter<W> {
|
||||
/// Returns the total number of bytes written since construction or the
|
||||
/// last time `reset` was called.
|
||||
pub fn count(&self) -> u64 {
|
||||
pub(crate) fn count(&self) -> u64 {
|
||||
self.count
|
||||
}
|
||||
|
||||
/// Returns the total number of bytes written since construction.
|
||||
pub fn total_count(&self) -> u64 {
|
||||
pub(crate) fn total_count(&self) -> u64 {
|
||||
self.total_count + self.count
|
||||
}
|
||||
|
||||
/// Resets the number of bytes written to `0`.
|
||||
pub fn reset_count(&mut self) {
|
||||
pub(crate) fn reset_count(&mut self) {
|
||||
self.total_count += self.count;
|
||||
self.count = 0;
|
||||
}
|
||||
@@ -40,21 +40,21 @@ impl<W> CounterWriter<W> {
|
||||
/// After this call, the total count of bytes written to the underlying
|
||||
/// writer is erased and reset.
|
||||
#[allow(dead_code)]
|
||||
pub fn clear(&mut self) {
|
||||
pub(crate) fn clear(&mut self) {
|
||||
self.count = 0;
|
||||
self.total_count = 0;
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn get_ref(&self) -> &W {
|
||||
pub(crate) fn get_ref(&self) -> &W {
|
||||
&self.wtr
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self) -> &mut W {
|
||||
pub(crate) fn get_mut(&mut self) -> &mut W {
|
||||
&mut self.wtr
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> W {
|
||||
pub(crate) fn into_inner(self) -> W {
|
||||
self.wtr
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user