Skip to content

Instantly share code, notes, and snippets.

@lankydan
Created May 20, 2018 16:43
Show Gist options
  • Save lankydan/c5e8a203cad89fad50d686c072a7a1b8 to your computer and use it in GitHub Desktop.
Save lankydan/c5e8a203cad89fad50d686c072a7a1b8 to your computer and use it in GitHub Desktop.
Building a REST API with Rust, Rocket and Diesel - handler all function
#[get("/")]
fn all(connection: DbConn) -> Result<Json<Vec<Person>>, Failure> {
people::repository::all(&connection)
.map(|people| Json(people))
.map_err(|error| error_status(error))
}
fn error_status(error: Error) -> Failure {
Failure(match error {
Error::NotFound => Status::NotFound,
_ => Status::InternalServerError
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment