Fix the Result
This function should return a Result, but it's returning raw values instead of wrapping them in Ok and Err! Fix the function.
Fix the code so it prints:
text
Positive: 5 Not positive: number must be positive
Hint: Wrap the return values in Ok(...) and Err(...).
rust
fn check_positive(n: i32) -> Result<i32, String> {
if n > 0 {
n
} else {
String::from("number must be positive")
}
}
fn main() {
match check_positive(5) {
Ok(n) => println!("Positive: {}", n),
Err(e) => println!("Not positive: {}", e),
}
match check_positive(-3) {
Ok(n) => println!("Positive: {}", n),
Err(e) => println!("Not positive: {}", e),
}
}