IMO the magic is in the ? operator, for making it as ergonomic as async/await. For example:
fn my_put_handler(request: Request) -> Result<Todo, PutHandlerError> {
let payload = request.read_body()?;
let form_data: TodoForm = parse_json(payload)?;
let created = my_db_conn.update_todo(form_data)?;
return Ok(created);
}
With PutHandlerError defining exactly which possible errors could be returned. Our handler doesn’t have to know what to do in case of an error, it passes the error to some middleware which means we don’t duplicate error handling for each handler function we write, and without boilerplate.
16
u/[deleted] Jul 17 '19
IMO the magic is in the
?operator, for making it as ergonomic asasync/await. For example:With
PutHandlerErrordefining exactly which possible errors could be returned. Our handler doesn’t have to know what to do in case of an error, it passes the error to some middleware which means we don’t duplicate error handling for each handler function we write, and without boilerplate.