expression
StatusCode: interpret response classes
Use status classes for broad branching, then inspect specific codes and response contracts. A successful status does not establish that the body matches the expected schema. External crate example; constructs data in memory, does not send requests. Expected stdout (not executed): 201 true false false 404 false true false 503 false false true true Common mistake: Treating every non-200 response as the same error.
Formal Syntax & Structure
rust syntaxrust
StatusCode::from_u16(n); is_success(); is_client_error(); is_server_error()Working Example
Example Snippetrust
fn main() { use http::StatusCode; for n in [201, 404, 503] { let s = StatusCode::from_u16(n).unwrap(); println!("{n} {} {} {}", s.is_success(), s.is_client_error(), s.is_server_error()); } println!("{}", StatusCode::from_u16(42).is_err());}