1
0
Fork 0
mirror of https://github.com/tokio-rs/axum.git synced 2025-04-26 13:56:22 +02:00
This commit is contained in:
Yann Simon 2024-10-23 15:16:59 +02:00
parent b110d55a58
commit 74842f30ad
No known key found for this signature in database

View file

@ -2,6 +2,7 @@ use std::{
collections::HashMap,
convert::Infallible,
marker::PhantomData,
sync::Arc,
task::{Context, Poll},
};
@ -20,7 +21,7 @@ trait CommandFromBody {
}
struct ExampleService<C> {
routes: HashMap<String, MethodRouter>,
routes: Arc<HashMap<String, MethodRouter>>,
_phantom_c: PhantomData<fn() -> C>,
}
@ -37,6 +38,7 @@ where
}
fn call(&mut self, req: Request) -> Self::Future {
let routes = self.routes.clone();
async move {
let (parts, body) = req.into_parts();
@ -44,7 +46,7 @@ where
return Ok(StatusCode::INTERNAL_SERVER_ERROR.into_response());
};
match C::command_from_body(&bytes).and_then(|cmd| self.routes.get(cmd)) {
match C::command_from_body(&bytes).and_then(|cmd| routes.get(cmd)) {
Some(router) => {
let req = Request::from_parts(parts, Body::from(bytes));