From 8ce5d8eb8704e04503323dd0b0c6649ccc5b581d Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 30 Oct 2024 05:31:34 +0000 Subject: [PATCH] reserve outgoing request headers Signed-off-by: Jason Volk --- crates/ruma-macros/src/api/request/outgoing.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/ruma-macros/src/api/request/outgoing.rs b/crates/ruma-macros/src/api/request/outgoing.rs index 6bac6d2c..38b96785 100644 --- a/crates/ruma-macros/src/api/request/outgoing.rs +++ b/crates/ruma-macros/src/api/request/outgoing.rs @@ -99,6 +99,7 @@ impl Request { let (impl_generics, ty_generics, where_clause) = self.generics.split_for_impl(); + let reserve_headers = 1 + self.header_fields().count(); quote! { #[automatically_derived] #[cfg(feature = "client")] @@ -124,7 +125,10 @@ impl Request { )?); if let Some(mut req_headers) = req_builder.headers_mut() { + req_headers.reserve(#reserve_headers); #header_kvs + + debug_assert!(#reserve_headers >= req_headers.len(), "not enough headers reserved"); } let http_request = req_builder.body(#request_body)?;