From fed7d4a986a671ab0ad32d4f68faa1419d779804 Mon Sep 17 00:00:00 2001 From: Shannon Skipper Date: Wed, 20 Nov 2024 05:22:43 -0800 Subject: [PATCH] Update documentation --- src/filters.rs | 17 +++++++---------- src/input.rs | 6 +++--- src/options.rs | 4 ++-- src/output.rs | 4 ++-- src/verbose.rs | 2 +- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/filters.rs b/src/filters.rs index c286c25..ef90e6c 100644 --- a/src/filters.rs +++ b/src/filters.rs @@ -4,33 +4,30 @@ use indexmap::IndexMap; use std::collections::HashSet; use unicode_segmentation::UnicodeSegmentation; -/// Filters for words to be included in the tally. +/// Filters for which words should be tallied. #[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord, Hash)] pub struct Filters { - /// Word chars filters for tallying. + /// Minimum characters required for a word. pub min_chars: Option, - /// Word count filters for tallying. + /// Minimum count for number of times a word must appear. pub min_count: Option, - /// List of specific words to exclude for tallying. + /// List of specific words to exclude. pub exclude: Option, } impl Filters { /// Removes words from the `tally_map` based on any word `Filters`. pub fn apply(&self, tally_map: &mut IndexMap, usize>, case: Case) { - // Remove any words that lack the minimum count. if let Some(MinCount(min_count)) = self.min_count { tally_map.retain(|_, &mut count| count >= min_count); } - // Remove any words that lack the minimum numbner of characters. if let Some(MinChars(min_chars)) = self.min_chars { tally_map.retain(|word, _| word.graphemes(true).count() >= min_chars); } - // Remove any words on the `discard` list. if let Some(ExcludeWords(words)) = &self.exclude { let discard: HashSet<_> = words.iter().map(|word| case.apply_and_box(word)).collect(); tally_map.retain(|word, _| !discard.contains(word)); @@ -38,7 +35,7 @@ impl Filters { } } -/// Min number of chars a word needs to be tallied. +/// Minimum number of characters a word needs to have to be tallied. #[derive(Clone, Copy, Debug, Default, Eq, PartialEq, PartialOrd, Ord, Hash)] pub struct MinChars(pub usize); @@ -54,7 +51,7 @@ impl From for MinChars { } } -/// Min count a word needs to be tallied. +/// Minimum number of times a word needs to appear to be tallied. #[derive(Clone, Copy, Debug, Default, Eq, PartialEq, PartialOrd, Ord, Hash)] pub struct MinCount(pub usize); @@ -70,7 +67,7 @@ impl From for MinCount { } } -/// A list of words that should not be tallied. +/// A list of words that should be omitted from the tally. #[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord, Hash)] pub struct ExcludeWords(pub Vec); diff --git a/src/input.rs b/src/input.rs index fada3b7..2459681 100644 --- a/src/input.rs +++ b/src/input.rs @@ -3,7 +3,7 @@ use std::fs::File; use std::io::{self, Read}; use std::path::PathBuf; -/// `Input` from a file or stdin input source. +/// `Input` to read from a file or stdin source. pub enum Input { File(PathBuf), Stdin, @@ -19,7 +19,7 @@ impl Input { } } - /// Gets the reader for the input source. + /// Gets the reader from the input source. pub fn get_reader(&self) -> Result> { match self { Self::File(path) => { @@ -31,7 +31,7 @@ impl Input { } } - /// Returns the file name of the input or `"-"` for STDIN. + /// Returns the file name of the input or `"-"` for stdin. pub fn source(&self) -> String { match self { Self::File(path) => path diff --git a/src/options.rs b/src/options.rs index bd6d0ee..0749355 100644 --- a/src/options.rs +++ b/src/options.rs @@ -3,14 +3,14 @@ use clap::ValueEnum; use core::cmp::Reverse; use core::fmt::{self, Display, Formatter}; -// Tallying options. +/// Tallying options. #[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Hash)] pub struct Options { pub case: Case, pub sort: Sort, } -/// Word case normalization. +/// Word case normalization options. #[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Hash, ValueEnum)] pub enum Case { Original, diff --git a/src/output.rs b/src/output.rs index 8cc4dd0..1e94277 100644 --- a/src/output.rs +++ b/src/output.rs @@ -3,10 +3,10 @@ use std::fs::File; use std::io::{self, ErrorKind::BrokenPipe, LineWriter, Write}; use std::path::{Path, PathBuf}; -/// `Writer` is a boxed type for dynamic dispatch of the `Write` trait. +/// `Writer` dynamic dispatches the `Write` trait. pub type Writer = Box; -/// `Output` manages writing to either a file, stdout, or stderr. +/// `Output` writes to either a file or stream like stdout or stderr. pub struct Output { writer: Writer, } diff --git a/src/verbose.rs b/src/verbose.rs index 4206562..2f1e767 100644 --- a/src/verbose.rs +++ b/src/verbose.rs @@ -47,7 +47,7 @@ impl Verbose { Ok(()) } - /// Format `"none"` or a `usize` as a `String`. + /// Format the `usize`, or `"none"` if none, as a `String`. fn format(&self, value: Option) -> String { value.map_or_else(|| "none".to_string(), |v| v.to_string()) }