{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/38300","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/38300/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/38300/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/38300/events","html_url":"https://github.com/rust-lang/rust/issues/38300","id":194840551,"number":38300,"title":"The Book should document, and use, the idiomatic way to exit unsuccessfully without panicing","user":{"login":"zackw","id":325899,"avatar_url":"https://avatars.githubusercontent.com/u/325899?v=3","gravatar_id":"","url":"https://api.github.com/users/zackw","html_url":"https://github.com/zackw","followers_url":"https://api.github.com/users/zackw/followers","following_url":"https://api.github.com/users/zackw/following{/other_user}","gists_url":"https://api.github.com/users/zackw/gists{/gist_id}","starred_url":"https://api.github.com/users/zackw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zackw/subscriptions","organizations_url":"https://api.github.com/users/zackw/orgs","repos_url":"https://api.github.com/users/zackw/repos","events_url":"https://api.github.com/users/zackw/events{/privacy}","received_events_url":"https://api.github.com/users/zackw/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-12-11T16:23:13Z","updated_at":"2016-12-11T17:46:36Z","closed_at":null,"body":"`main` in a Rust program returns no value, AFAICT (I can't find any *reference* documentation for `main`, but all the examples just do `fn main() {` ).  All of the examples in The Book either panic or exit normally (even in error cases), and process exit statuses are not mentioned anywhere.  This is Wrong.  The Book should document the idiomatic way to exit unsuccessfully _without_ panicing, and all of the example programs should use that method when appropriate.\r\n\r\nTake for instance this example from https://doc.rust-lang.org/book/error-handling.html#parsing-integers:\r\n\r\n```\r\nuse std::num::ParseIntError;\r\n\r\nfn double_number(number_str: &str) -> Result<i32, ParseIntError> {\r\n    match number_str.parse::<i32>() {\r\n        Ok(n) => Ok(2 * n),\r\n        Err(err) => Err(err),\r\n    }\r\n}\r\n\r\nfn main() {\r\n    match double_number(\"10\") {\r\n        Ok(n) => assert_eq!(n, 20),\r\n        Err(err) => println!(\"Error: {:?}\", err),\r\n    }\r\n}\r\n```\r\n\r\nThe `Err` case in `main` should cause the program to exit unsuccessfully, but without panicing.\r\n\r\nRelated, I can't figure out what the idiomatic way to exit unsuccessfully without panicing actually _is_.  The only thing I've found is `std::process::exit`, whose documentation makes it sound like it is _not_ the correct thing to use (e.g. dire warnings about not running destructors).\r\n\r\nThe basic `grep` exit-status convention should be mentioned at some point (code 0 = no error, matches found; code 1 = no error, no matches found; code 2 = error occurred)."},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/266295937","html_url":"https://github.com/rust-lang/rust/issues/38300#issuecomment-266295937","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/38300","id":266295937,"user":{"login":"zackw","id":325899,"avatar_url":"https://avatars.githubusercontent.com/u/325899?v=3","gravatar_id":"","url":"https://api.github.com/users/zackw","html_url":"https://github.com/zackw","followers_url":"https://api.github.com/users/zackw/followers","following_url":"https://api.github.com/users/zackw/following{/other_user}","gists_url":"https://api.github.com/users/zackw/gists{/gist_id}","starred_url":"https://api.github.com/users/zackw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zackw/subscriptions","organizations_url":"https://api.github.com/users/zackw/orgs","repos_url":"https://api.github.com/users/zackw/repos","events_url":"https://api.github.com/users/zackw/events{/privacy}","received_events_url":"https://api.github.com/users/zackw/received_events","type":"User","site_admin":false},"created_at":"2016-12-11T17:46:35Z","updated_at":"2016-12-11T17:46:35Z","body":"@nagisa That's reasonably tidy, and I can see how it's safe in a single-threaded program (everything needing destroying must have been destroyed by the time `run_your_app` returns, with the _possible_ exception of stdout and stderr).  But what about multithreaded programs?  \"Make sure to join all threads before returning from `run_your_app`\" might be good enough until you start worrying about invisible thread pools in libraries ..."}}
{"actor":{"display_login":"zackw"}}