mirror of
https://github.com/tokio-rs/axum.git
synced 2025-04-26 13:56:22 +02:00
use Arc
This commit is contained in:
parent
b110d55a58
commit
74842f30ad
1 changed files with 4 additions and 2 deletions
|
@ -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));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue