Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn only_positive(n: i32) -> Option<i32> {
- if n > 0 {
- return Some(n);
- }
- None
- }
- fn main() {
- let x = 5;
- let y = -6;
- match only_positive(x) {
- Some(value) => println!("The value is {}", value),
- None => println!("x is not positive")
- }
- match only_positive(y) {
- Some(value) => println!("The value is {}", value),
- None => println!("y is not positive")
- }
- }
Add Comment
Please, Sign In to add comment