Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. #![allow(unreachable_code)]
  2.  
  3. fn redirect() -> ! {
  4. std::process::exit(0) // A redirect will never return to the calling code
  5. }
  6.  
  7. fn my_calling_code(num: i32) -> i32 {
  8. if num > 0 {
  9. return 5;
  10. } else {
  11. return redirect(); // If a function never returns, the type system says it returns absolutely anything
  12. }
  13. }
  14.  
  15. fn main() {
  16. println!("{:?}", my_calling_code(1));
  17. println!("{:?}", my_calling_code(-1));
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement