1
0
Fork 0
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 ()

This commit is contained in:
Cole 2023-02-11 13:44:48 -08:00 committed by GitHub
parent 93ecabf449
commit 5c58b4ffde
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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()))
}
}
}