mirror of
https://github.com/ahgamut/rust-ape-example.git
synced 2024-05-29 00:38:05 +00:00
29 lines
596 B
Rust
29 lines
596 B
Rust
|
// ./src/error/result/enter_question_mark.md
|
||
|
|
||
|
|
||
|
use std::num::ParseIntError;
|
||
|
|
||
|
fn multiply(first_number_str: &str, second_number_str: &str) -> Result<i32, ParseIntError> {
|
||
|
let first_number = first_number_str.parse::<i32>()?;
|
||
|
let second_number = second_number_str.parse::<i32>()?;
|
||
|
|
||
|
Ok(first_number * second_number)
|
||
|
}
|
||
|
|
||
|
fn print(result: Result<i32, ParseIntError>) {
|
||
|
match result {
|
||
|
Ok(n) => println!("n is {}", n),
|
||
|
Err(e) => println!("Error: {}", e),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn part0() {
|
||
|
print(multiply("10", "2"));
|
||
|
print(multiply("t", "2"));
|
||
|
}
|
||
|
|
||
|
pub fn main() {
|
||
|
part0();
|
||
|
}
|
||
|
|