~irimi1/learning-rust

41510e68675b91905d3af538ae41db4591ed8c5a — Manuel Groß 2 years ago ba98aa6
minigrep: Make run() return a result
1 files changed, 5 insertions(+), 3 deletions(-)

M projects/minigrep/src/main.rs
M projects/minigrep/src/main.rs => projects/minigrep/src/main.rs +5 -3
@@ 1,4 1,5 @@
use std::env;
use std::error::Error;
use std::fs;
use std::process;



@@ 16,11 17,12 @@ fn main() {
    run(config);
}

fn run(config: Config) {
    let contents = fs::read_to_string(config.filename)
        .expect("Something went wrong reading the file");
fn run(config: Config) -> Result<(), Box<dyn Error>> {
    let contents = fs::read_to_string(config.filename)?;

    println!("With text:\n{}", contents);

    Ok(())
}

struct Config {