I'm a Rust novice and trying to read in two numbers and calculate their quotient:
use std::io;
enum Option<T> {
None,
Some(T),
}
fn safe_div(n: i32, d: i32) -> Option<i32> {
if d == 0 {
return None;
}
return Some(n / d);
}
fn main() {
println!("Please input your numerator.");
let mut numerator = String::new();
io::stdin()
.read_line(&mut numerator)
.expect("Failed to read line");
println!("Please input your denominator.");
let mut denominator = String::new();
io::stdin()
.read_line(&mut denominator)
.expect("Failed to read line");
match safe_div(numerator, denominator) {
None => println!("Can't divide by zero!"),
Some(v) => println!("Quotient is {}", v),
}
}
but I am getting the following error repeated several times when I try to compile it:
src/safe_div.rs:12:12: 12:21 error: mismatched types: expected
Option<i32>
, foundstd::option::Option<i32>
(expected enumOption
, found enumstd::option::Option
) [E0308]
What am I missing here?