diff --git a/axum-core/src/extract/from_ref.rs b/axum-core/src/extract/from_ref.rs index c0124140..7a674e75 100644 --- a/axum-core/src/extract/from_ref.rs +++ b/axum-core/src/extract/from_ref.rs @@ -1,3 +1,5 @@ +use std::borrow::Borrow; + /// Used to do reference-to-value conversions thus not consuming the input value. /// /// This is mainly used with [`State`] to extract "substates" from a reference to main application @@ -13,11 +15,12 @@ pub trait FromRef { fn from_ref(input: &T) -> Self; } -impl FromRef for T +impl FromRef for U where - T: Clone, + T: Borrow, + U: Clone, { fn from_ref(input: &T) -> Self { - input.clone() + input.borrow().clone() } } diff --git a/axum/src/routing/tests/merge.rs b/axum/src/routing/tests/merge.rs index 804549d3..41b4355e 100644 --- a/axum/src/routing/tests/merge.rs +++ b/axum/src/routing/tests/merge.rs @@ -469,7 +469,7 @@ async fn merging_routes_different_paths_different_states() { #[tokio::test] async fn inherit_state_via_merge() { - let foo = Router::inherit_state().route( + let foo = Router::<&'static str>::inherit_state().route( "/foo", get(|State(state): State<&'static str>| async move { state }), ); diff --git a/axum/src/routing/tests/nest.rs b/axum/src/routing/tests/nest.rs index 42c4ffe9..dda151e1 100644 --- a/axum/src/routing/tests/nest.rs +++ b/axum/src/routing/tests/nest.rs @@ -473,7 +473,7 @@ async fn nesting_with_different_state() { #[tokio::test] async fn inherit_state_via_nest() { - let foo = Router::inherit_state().route( + let foo = Router::<&'static str>::inherit_state().route( "/foo", get(|State(state): State<&'static str>| async move { state }), );