mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-29 00:00:18 +02:00
Improve value and reference passing efficiency (#3406)
This commit is contained in:
@@ -206,7 +206,7 @@ impl IntoResponseParts for CookieJar {
|
||||
type Error = Infallible;
|
||||
|
||||
fn into_response_parts(self, mut res: ResponseParts) -> Result<ResponseParts, Self::Error> {
|
||||
set_cookies(self.jar, res.headers_mut());
|
||||
set_cookies(&self.jar, res.headers_mut());
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
@@ -217,7 +217,7 @@ impl IntoResponse for CookieJar {
|
||||
}
|
||||
}
|
||||
|
||||
fn set_cookies(jar: cookie::CookieJar, headers: &mut HeaderMap) {
|
||||
fn set_cookies(jar: &cookie::CookieJar, headers: &mut HeaderMap) {
|
||||
for cookie in jar.delta() {
|
||||
if let Ok(header_value) = cookie.encoded().to_string().parse() {
|
||||
headers.append(SET_COOKIE, header_value);
|
||||
|
||||
@@ -274,7 +274,7 @@ impl<K> IntoResponseParts for PrivateCookieJar<K> {
|
||||
type Error = Infallible;
|
||||
|
||||
fn into_response_parts(self, mut res: ResponseParts) -> Result<ResponseParts, Self::Error> {
|
||||
set_cookies(self.jar, res.headers_mut());
|
||||
set_cookies(&self.jar, res.headers_mut());
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ impl<K> IntoResponseParts for SignedCookieJar<K> {
|
||||
type Error = Infallible;
|
||||
|
||||
fn into_response_parts(self, mut res: ResponseParts) -> Result<ResponseParts, Self::Error> {
|
||||
set_cookies(self.jar, res.headers_mut());
|
||||
set_cookies(&self.jar, res.headers_mut());
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ mod tests {
|
||||
|
||||
let app = Router::new().route(
|
||||
"/",
|
||||
post(|input: Protobuf<Input>| async move { input.foo.to_owned() }),
|
||||
post(|Protobuf(input): Protobuf<Input>| async move { input.foo }),
|
||||
);
|
||||
|
||||
let input = Input {
|
||||
@@ -228,10 +228,8 @@ mod tests {
|
||||
}
|
||||
|
||||
#[axum::debug_handler]
|
||||
async fn handler(input: Protobuf<Input>) -> Protobuf<Output> {
|
||||
let output = Output {
|
||||
result: input.foo.to_owned(),
|
||||
};
|
||||
async fn handler(Protobuf(input): Protobuf<Input>) -> Protobuf<Output> {
|
||||
let output = Output { result: input.foo };
|
||||
|
||||
Protobuf(output)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user