Skip to content

Instantly share code, notes, and snippets.

@hussachai
Created April 2, 2022 05:52
Show Gist options
  • Save hussachai/1981aa25dd5855e5548b0fe341424ca0 to your computer and use it in GitHub Desktop.
Save hussachai/1981aa25dd5855e5548b0fe341424ca0 to your computer and use it in GitHub Desktop.
Error Handling in Rust that Every Beginner should Know (actix-web-handler)
// main.rs
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(move || {
App::new()
.service(web::resource("/queue/{id}").route(web::get().to(queue_handler::handle)))
}).bind("0.0.0.0:8080")?.run().await
}
// queue_handler.rs
pub async fn handle(pool: web::Data<Pool>) -> Result<HttpResponse, Error> {
...
let connection = pool.get().await?;
let channel = connection.create_channel().await?;
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment