Guest User

Untitled

a guest
May 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. fn only_positive(n: i32) -> Option<i32> {
  2. if n > 0 {
  3. return Some(n);
  4. }
  5. None
  6. }
  7.  
  8. fn main() {
  9. let x = 5;
  10. let y = -6;
  11.  
  12. match only_positive(x) {
  13. Some(value) => println!("The value is {}", value),
  14. None => println!("x is not positive")
  15. }
  16.  
  17. match only_positive(y) {
  18. Some(value) => println!("The value is {}", value),
  19. None => println!("y is not positive")
  20. }
  21. }
Add Comment
Please, Sign In to add comment