api: Slightly optimize OutgoingRequest implementations

This commit is contained in:
Jonas Platte 2021-04-23 13:37:13 +02:00
parent f818b53ca1
commit 1e005f576e
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
2 changed files with 7 additions and 7 deletions

View File

@ -138,12 +138,12 @@ impl Request {
#( #attrs )* #( #attrs )*
req_headers.insert( req_headers.insert(
#http::header::AUTHORIZATION, #http::header::AUTHORIZATION,
#http::header::HeaderValue::from_str(&::std::format!( ::std::convert::TryFrom::<_>::try_from(::std::format!(
"Bearer {}", "Bearer {}",
access_token access_token
.get_required() .get_required()
.ok_or(#ruma_api::error::IntoHttpError::NeedsAuthentication)?, .ok_or(#ruma_api::error::IntoHttpError::NeedsAuthentication)?,
))? ))?,
); );
} }
} else { } else {
@ -152,8 +152,8 @@ impl Request {
#( #attrs )* #( #attrs )*
req_headers.insert( req_headers.insert(
#http::header::AUTHORIZATION, #http::header::AUTHORIZATION,
#http::header::HeaderValue::from_str( ::std::convert::TryFrom::<_>::try_from(
&::std::format!("Bearer {}", access_token) ::std::format!("Bearer {}", access_token),
)? )?
); );
} }

View File

@ -73,7 +73,7 @@ impl<'a> ruma_api::OutgoingRequest for Request<'a> {
) -> Result<http::Request<T>, ruma_api::error::IntoHttpError> { ) -> Result<http::Request<T>, ruma_api::error::IntoHttpError> {
use std::borrow::Cow; use std::borrow::Cow;
use http::header::{self, HeaderValue}; use http::header;
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
let mut url = format!( let mut url = format!(
@ -94,12 +94,12 @@ impl<'a> ruma_api::OutgoingRequest for Request<'a> {
.header(header::CONTENT_TYPE, "application/json") .header(header::CONTENT_TYPE, "application/json")
.header( .header(
header::AUTHORIZATION, header::AUTHORIZATION,
HeaderValue::from_str(&format!( format!(
"Bearer {}", "Bearer {}",
access_token access_token
.get_required() .get_required()
.ok_or(ruma_api::error::IntoHttpError::NeedsAuthentication)?, .ok_or(ruma_api::error::IntoHttpError::NeedsAuthentication)?,
))?, ),
) )
.body(T::default()) .body(T::default())
.map_err(Into::into) .map_err(Into::into)