From 1e005f576e4640ee5ce6e357bcf33293819502d1 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 23 Apr 2021 13:37:13 +0200 Subject: [PATCH] api: Slightly optimize OutgoingRequest implementations --- ruma-api-macros/src/api/request/outgoing.rs | 8 ++++---- ruma-client-api/src/r0/state/get_state_events_for_key.rs | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ruma-api-macros/src/api/request/outgoing.rs b/ruma-api-macros/src/api/request/outgoing.rs index f53d5cd5..5a82870b 100644 --- a/ruma-api-macros/src/api/request/outgoing.rs +++ b/ruma-api-macros/src/api/request/outgoing.rs @@ -138,12 +138,12 @@ impl Request { #( #attrs )* req_headers.insert( #http::header::AUTHORIZATION, - #http::header::HeaderValue::from_str(&::std::format!( + ::std::convert::TryFrom::<_>::try_from(::std::format!( "Bearer {}", access_token .get_required() .ok_or(#ruma_api::error::IntoHttpError::NeedsAuthentication)?, - ))? + ))?, ); } } else { @@ -152,8 +152,8 @@ impl Request { #( #attrs )* req_headers.insert( #http::header::AUTHORIZATION, - #http::header::HeaderValue::from_str( - &::std::format!("Bearer {}", access_token) + ::std::convert::TryFrom::<_>::try_from( + ::std::format!("Bearer {}", access_token), )? ); } diff --git a/ruma-client-api/src/r0/state/get_state_events_for_key.rs b/ruma-client-api/src/r0/state/get_state_events_for_key.rs index c4719b9b..3381342a 100644 --- a/ruma-client-api/src/r0/state/get_state_events_for_key.rs +++ b/ruma-client-api/src/r0/state/get_state_events_for_key.rs @@ -73,7 +73,7 @@ impl<'a> ruma_api::OutgoingRequest for Request<'a> { ) -> Result, ruma_api::error::IntoHttpError> { use std::borrow::Cow; - use http::header::{self, HeaderValue}; + use http::header; use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; let mut url = format!( @@ -94,12 +94,12 @@ impl<'a> ruma_api::OutgoingRequest for Request<'a> { .header(header::CONTENT_TYPE, "application/json") .header( header::AUTHORIZATION, - HeaderValue::from_str(&format!( + format!( "Bearer {}", access_token .get_required() .ok_or(ruma_api::error::IntoHttpError::NeedsAuthentication)?, - ))?, + ), ) .body(T::default()) .map_err(Into::into)