Skip to content

Commit 4fdf0f4

Browse files
committed
Tried to fix errors
1 parent f8fffa7 commit 4fdf0f4

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ repository = "https://github.com/Raphdf201/minigrep"
1111
keywords = ["cli", "grep", "search"]
1212

1313
[dependencies]
14+
anyhow = "1.0"
1415

1516
[profile.dev]
1617
opt-level = 0
1718

1819
[profile.release]
19-
opt-level = 3
20+
opt-level = 3

src/lib.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
//! # minigrep lib
2-
//!
3-
//! A library for my minigrep project
4-
51
use std::env;
6-
use std::error::Error;
72
use std::fmt::Result;
83
use std::fs;
94

10-
/// Runs the search engine,
11-
/// reads the file specified in the filename argument and
12-
/// outputs the lines of the file that contain the query
13-
pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
5+
use anyhow::Error;
6+
7+
pub fn run(config: Config) -> Result {
148
let contents = fs::read_to_string(config.filename)?;
159

1610
let results = if config.case_sensitive {
@@ -26,32 +20,26 @@ pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
2620
Ok(())
2721
}
2822

29-
/// Contains the fields for the search engine/arguments
3023
pub struct Config {
3124
pub query: String,
3225
pub filename: String,
3326
pub case_sensitive: bool,
3427
}
3528

3629
impl Config {
37-
pub fn new(args: &[String]) -> Result<Config, &str> {
30+
pub fn new(args: &[String]) -> Result<Config, Error> {
3831
if args.len() < 3 {
39-
return Err("Not enough arguments");
32+
return Err(Error::msg("Not enough arguments"));
4033
}
4134
let query: String = args[1].clone();
4235
let filename: String = args[2].clone();
4336

4437
let case_sensitive = env::var("CASE_INSENSITIVE").is_err();
4538

46-
Ok(Config {
47-
query,
48-
filename,
49-
case_sensitive,
50-
})
39+
Ok(())
5140
}
5241
}
5342

54-
/// Searches the query in a file
5543
pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> {
5644
let mut results = Vec::new();
5745

0 commit comments

Comments
 (0)