mirror of
https://github.com/tokio-rs/axum.git
synced 2025-10-02 15:24:54 +00:00
Avoid unnecessary clones of state in MethodRouter (#1745)
This commit is contained in:
parent
93ecabf449
commit
5c58b4ffde
@ -734,14 +734,14 @@ where
|
|||||||
/// Provide the state for the router.
|
/// Provide the state for the router.
|
||||||
pub fn with_state<S2>(self, state: S) -> MethodRouter<S2, B, E> {
|
pub fn with_state<S2>(self, state: S) -> MethodRouter<S2, B, E> {
|
||||||
MethodRouter {
|
MethodRouter {
|
||||||
get: self.get.with_state(state.clone()),
|
get: self.get.with_state(&state),
|
||||||
head: self.head.with_state(state.clone()),
|
head: self.head.with_state(&state),
|
||||||
delete: self.delete.with_state(state.clone()),
|
delete: self.delete.with_state(&state),
|
||||||
options: self.options.with_state(state.clone()),
|
options: self.options.with_state(&state),
|
||||||
patch: self.patch.with_state(state.clone()),
|
patch: self.patch.with_state(&state),
|
||||||
post: self.post.with_state(state.clone()),
|
post: self.post.with_state(&state),
|
||||||
put: self.put.with_state(state.clone()),
|
put: self.put.with_state(&state),
|
||||||
trace: self.trace.with_state(state.clone()),
|
trace: self.trace.with_state(&state),
|
||||||
allow_header: self.allow_header,
|
allow_header: self.allow_header,
|
||||||
fallback: self.fallback.with_state(state),
|
fallback: self.fallback.with_state(state),
|
||||||
}
|
}
|
||||||
@ -1217,12 +1217,12 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_state<S2>(self, state: S) -> MethodEndpoint<S2, B, E> {
|
fn with_state<S2>(self, state: &S) -> MethodEndpoint<S2, B, E> {
|
||||||
match self {
|
match self {
|
||||||
MethodEndpoint::None => MethodEndpoint::None,
|
MethodEndpoint::None => MethodEndpoint::None,
|
||||||
MethodEndpoint::Route(route) => MethodEndpoint::Route(route),
|
MethodEndpoint::Route(route) => MethodEndpoint::Route(route),
|
||||||
MethodEndpoint::BoxedHandler(handler) => {
|
MethodEndpoint::BoxedHandler(handler) => {
|
||||||
MethodEndpoint::Route(handler.into_route(state))
|
MethodEndpoint::Route(handler.into_route(state.clone()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user