From 963a3323ea6d91df24f2639bf377a8b37fe3ff1a Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 27 Dec 2022 16:06:55 +0100 Subject: [PATCH] Optimize: Remove clone() call This patch makes the `Headers` helper type that is only used to be able to implement Serialize on it only contain a reference to the actual headers. This way we don't need to clone() the object returned by `reqwest::Repsonse::headers()`. Signed-off-by: Matthias Beyer --- src/helpers/log.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/helpers/log.rs b/src/helpers/log.rs index 31f78cd..75dcb23 100644 --- a/src/helpers/log.rs +++ b/src/helpers/log.rs @@ -48,9 +48,9 @@ impl From<&reqwest::Response> for Status { /// Helper for logging request headers #[derive(Debug)] -pub struct Headers(pub reqwest::header::HeaderMap); +pub struct Headers<'h>(pub &'h reqwest::header::HeaderMap); -impl Serialize for Headers { +impl<'h> Serialize for Headers<'h> { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, @@ -63,8 +63,8 @@ impl Serialize for Headers { } } -impl From<&reqwest::Response> for Headers { - fn from(value: &reqwest::Response) -> Self { - Headers(value.headers().clone()) +impl<'h> From<&'h reqwest::Response> for Headers<'h> { + fn from(value: &'h reqwest::Response) -> Self { + Headers(value.headers()) } }