Created
April 2, 2022 05:52
-
-
Save hussachai/1981aa25dd5855e5548b0fe341424ca0 to your computer and use it in GitHub Desktop.
Error Handling in Rust that Every Beginner should Know (actix-web-handler)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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