Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![allow(unreachable_code)]
- fn redirect() -> ! {
- std::process::exit(0) // A redirect will never return to the calling code
- }
- fn my_calling_code(num: i32) -> i32 {
- if num > 0 {
- return 5;
- } else {
- return redirect(); // If a function never returns, the type system says it returns absolutely anything
- }
- }
- fn main() {
- println!("{:?}", my_calling_code(1));
- println!("{:?}", my_calling_code(-1));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement