Last active
April 11, 2019 13:25
-
-
Save Mec-iS/f0fc9065a920042cebfe6b8b239115b0 to your computer and use it in GitHub Desktop.
[RUST] Functions that are exception to uniformity of return type (forever loops, break, exits ...)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Taken from "Programming Rust" by Jim Blandy and Jason Orendorff | |
// Expressions that don’t finish normally are assigned the special type ! , | |
// and they’re exempt from the rules about types having to match. | |
// You can see ! in the function signature of `std::process::exit()`: | |
fn exit(code: i32) -> ! | |
// The ! means that exit() never returns. It’s a divergent function. | |
// You can write divergent functions of your own using the same syntax, | |
// and this is perfectly natural in some cases: | |
fn serve_forever(socket: ServerSocket, handler: ServerHandler) -> ! { | |
socket.listen(); | |
loop { | |
let s = socket.accept(); | |
handler.handle(s); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment