From 74842f30ad964d49e22b5d6055dc9dd30e81e0c0 Mon Sep 17 00:00:00 2001 From: Yann Simon Date: Wed, 23 Oct 2024 15:16:59 +0200 Subject: [PATCH] use Arc --- axum-extra/src/test_method_routing.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/axum-extra/src/test_method_routing.rs b/axum-extra/src/test_method_routing.rs index 173ac560..43792906 100644 --- a/axum-extra/src/test_method_routing.rs +++ b/axum-extra/src/test_method_routing.rs @@ -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 { - routes: HashMap, + routes: Arc>, _phantom_c: PhantomData 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));