basic error handling
This commit is contained in:
parent
ea61afade2
commit
fcd70e2c4e
1 changed files with 8 additions and 4 deletions
12
src/main.rs
12
src/main.rs
|
@ -6,8 +6,12 @@ struct Cli {
|
||||||
path: std::path::PathBuf,
|
path: std::path::PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let args = Cli::parse();
|
let result = std::fs::read_to_string("test.txt");
|
||||||
|
let content = match result {
|
||||||
println!("pattern: {:?}, path: {:?}", args.pattern, args.path);
|
Ok(content) => { content },
|
||||||
|
Err(error) => { return Err(error.into()); },
|
||||||
|
};
|
||||||
|
println!("file content: {}", content);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue