look at the difference

WITH

fn read_bitcoin_file(file_name: &str) -> Result {

let mut bitcoin_file = File::open(file_name)?;

let mut bitcoin_amount = String::new();

bitcoin_file.read_to_string(&mut bitcoin_amount)?;

let amount: f64 = bitcoin_amount.trim().parse().unwrap();

Ok(amount)

}

WITHOUT

fn read_bitcoin_file(file_name: &str) -> Result {

let bitcoin_file_result = File::open(file_name);

let mut bitcoin_file = match bitcoin_file_result {

Ok(bf) => bf,

Err(e) => return Err(e),

};

let mut bitcoin_amount = String::new();

let bitcoin_amount = match bitcoin_file.read_to_string(&mut bitcoin_amount) {

Ok(_) => bitcoin_amount,

Err(e) => return Err(e),

};

let bitcoin_amount = bitcoin_amount.trim().parse::().unwrap();

Ok(bitcoin_amount)

}

Reply to this note

Please Login to reply.

Discussion

No replies yet.