From bd5d14dbf04d20510bf90d834baa4dea533aebee Mon Sep 17 00:00:00 2001 From: PiyushXCoder Date: Sat, 9 May 2020 20:30:20 +0530 Subject: [PATCH] docs --- src/lib.rs | 9 ++++++--- src/main.rs | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 74ccac9..e2b43ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ use std::error::Error; use std::fs; +/// Configuration to contain basic information of file and match operation pub struct Configs { pattern: String, filename: String, @@ -8,6 +9,7 @@ pub struct Configs { } impl Configs { + /// create new configuration pub fn new(args: &mut std::env::Args) -> Result { if args.len() < 3 { return Err("\ @@ -40,6 +42,7 @@ adding \"case\" is optional to enable case sensitive grep"); } } +/// processing point of program pub fn run(conf: Configs) -> Result<(), Box> { let contents: String = fs::read_to_string(conf.filename)?; @@ -52,7 +55,7 @@ pub fn run(conf: Configs) -> Result<(), Box> { Ok(()) } -pub fn search_case_sensitive<'a>(pattern: &str, contents: &'a str) -> Vec<&'a str> { +fn search_case_sensitive<'a>(pattern: &str, contents: &'a str) -> Vec<&'a str> { contents.lines() .filter( |lin| lin @@ -60,7 +63,7 @@ pub fn search_case_sensitive<'a>(pattern: &str, contents: &'a str) -> Vec<&'a st .collect() } -pub fn search_case_insensitive<'a>(pattern: &str, contents: &'a str) -> Vec<&'a str> { +fn search_case_insensitive<'a>(pattern: &str, contents: &'a str) -> Vec<&'a str> { contents.lines() .filter( |lin| lin.to_lowercase() @@ -68,7 +71,7 @@ pub fn search_case_insensitive<'a>(pattern: &str, contents: &'a str) -> Vec<&'a .collect() } -pub fn print_output(out: Vec<&str>) { +fn print_output(out: Vec<&str>) { println!("matched: {}", out.len()); for x in out { println!("{}", x); diff --git a/src/main.rs b/src/main.rs index 438ac82..cd4e9fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,6 @@ +//! minigrep +//! Minimal grep program to sort out lines contaning text + use std::env; use std::process;