mirror of
https://github.com/tokio-rs/axum.git
synced 2025-04-16 02:30:56 +02:00
Avoid unnecessary clones of state in MethodRouter (#1745)
This commit is contained in:
parent
93ecabf449
commit
5c58b4ffde
1 changed files with 10 additions and 10 deletions
|
@ -734,14 +734,14 @@ where
|
|||
/// Provide the state for the router.
|
||||
pub fn with_state<S2>(self, state: S) -> MethodRouter<S2, B, E> {
|
||||
MethodRouter {
|
||||
get: self.get.with_state(state.clone()),
|
||||
head: self.head.with_state(state.clone()),
|
||||
delete: self.delete.with_state(state.clone()),
|
||||
options: self.options.with_state(state.clone()),
|
||||
patch: self.patch.with_state(state.clone()),
|
||||
post: self.post.with_state(state.clone()),
|
||||
put: self.put.with_state(state.clone()),
|
||||
trace: self.trace.with_state(state.clone()),
|
||||
get: self.get.with_state(&state),
|
||||
head: self.head.with_state(&state),
|
||||
delete: self.delete.with_state(&state),
|
||||
options: self.options.with_state(&state),
|
||||
patch: self.patch.with_state(&state),
|
||||
post: self.post.with_state(&state),
|
||||
put: self.put.with_state(&state),
|
||||
trace: self.trace.with_state(&state),
|
||||
allow_header: self.allow_header,
|
||||
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 {
|
||||
MethodEndpoint::None => MethodEndpoint::None,
|
||||
MethodEndpoint::Route(route) => MethodEndpoint::Route(route),
|
||||
MethodEndpoint::BoxedHandler(handler) => {
|
||||
MethodEndpoint::Route(handler.into_route(state))
|
||||
MethodEndpoint::Route(handler.into_route(state.clone()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue