{"action":"created","issue":{"url":"https://api.github.com/repos/hyperium/hyper/issues/700","labels_url":"https://api.github.com/repos/hyperium/hyper/issues/700/labels{/name}","comments_url":"https://api.github.com/repos/hyperium/hyper/issues/700/comments","events_url":"https://api.github.com/repos/hyperium/hyper/issues/700/events","html_url":"https://github.com/hyperium/hyper/pull/700","id":120080853,"number":700,"title":"feat(status): add StatusCodes scoped by StatusClass","user":{"login":"Ryman","id":994978,"avatar_url":"https://avatars.githubusercontent.com/u/994978?v=3","gravatar_id":"","url":"https://api.github.com/users/Ryman","html_url":"https://github.com/Ryman","followers_url":"https://api.github.com/users/Ryman/followers","following_url":"https://api.github.com/users/Ryman/following{/other_user}","gists_url":"https://api.github.com/users/Ryman/gists{/gist_id}","starred_url":"https://api.github.com/users/Ryman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ryman/subscriptions","organizations_url":"https://api.github.com/users/Ryman/orgs","repos_url":"https://api.github.com/users/Ryman/repos","events_url":"https://api.github.com/users/Ryman/events{/privacy}","received_events_url":"https://api.github.com/users/Ryman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-12-03T02:23:44Z","updated_at":"2015-12-29T04:56:41Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/hyperium/hyper/pulls/700","html_url":"https://github.com/hyperium/hyper/pull/700","diff_url":"https://github.com/hyperium/hyper/pull/700.diff","patch_url":"https://github.com/hyperium/hyper/pull/700.patch"},"body":"This enables users to limit their api to certain classes of `StatusCode`, e.g. if you only want to accept error codes you can do:\r\n\r\n```rust\r\nuse hyper::status::StatusCode;\r\nuse hyper::status::scoped;\r\n\r\ntrait HttpError {}\r\n\r\nimpl HttpError for scoped::ClientError {}\r\nimpl HttpError for scoped::ServerError {}\r\n\r\nfn only_accept_errors<E: HttpError + Into<StatusCode>>(error: E) {\r\n     let _status_code: StatusCode = error.into();\r\n     // ... use status code here ...\r\n}\r\n\r\n// Will not compile\r\n// only_accept_errors(scoped::Informational::Continue);\r\n\r\n// These work fine!\r\nonly_accept_errors(scoped::ClientError::BadRequest);\r\nonly_accept_errors(scoped::ServerError::InternalServerError);\r\n```\r\n\r\nThis is somewhat similar to the proposal [here](http://smallcultfollowing.com/babysteps/blog/2015/08/20/virtual-structs-part-3-bringing-enums-and-structs-together/), but since we're able to generate the StatusCodes by macro, it's a relatively minor change to get the added benefit, I think it can be worth it to just do it without the language feature assisting."},"comment":{"url":"https://api.github.com/repos/hyperium/hyper/issues/comments/167719111","html_url":"https://github.com/hyperium/hyper/pull/700#issuecomment-167719111","issue_url":"https://api.github.com/repos/hyperium/hyper/issues/700","id":167719111,"user":{"login":"reem","id":4745181,"avatar_url":"https://avatars.githubusercontent.com/u/4745181?v=3","gravatar_id":"","url":"https://api.github.com/users/reem","html_url":"https://github.com/reem","followers_url":"https://api.github.com/users/reem/followers","following_url":"https://api.github.com/users/reem/following{/other_user}","gists_url":"https://api.github.com/users/reem/gists{/gist_id}","starred_url":"https://api.github.com/users/reem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reem/subscriptions","organizations_url":"https://api.github.com/users/reem/orgs","repos_url":"https://api.github.com/users/reem/repos","events_url":"https://api.github.com/users/reem/events{/privacy}","received_events_url":"https://api.github.com/users/reem/received_events","type":"User","site_admin":false},"created_at":"2015-12-29T04:56:41Z","updated_at":"2015-12-29T04:56:41Z","body":"If we could somehow hint in that error to use Into then I think I would be for it but right now it's just not very newbie friendly."}}