You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement IntoHeaderName and IntoHeaderValue for an (owned) String, so no allocation is necessary (*).
(*) For HeaderName, the underlying does not allocate if the Vec has not leftover capacity (https://docs.rs/bytes/latest/src/bytes/bytes.rs.html#849-882), but still this is the best we can do. However, I assume that for HeaderName using &'static str is the more common case.
Use case
I have to use format! to build some complex HeaderValue. So far, I have to use my_value.as_str().into_header_value() which internally uses .to_string(), so it creates a new allocation for the string, and the old allocation gets just freed afterward. Maybe the compiler can optimize this allocation away, but maybe not...
Contribution
Yes. Preparing PR.
The text was updated successfully, but these errors were encountered:
Proposed change
Implement
IntoHeaderName
andIntoHeaderValue
for an (owned) String, so no allocation is necessary (*).(*) For
HeaderName
, the underlying does not allocate if theVec
has not leftover capacity (https://docs.rs/bytes/latest/src/bytes/bytes.rs.html#849-882), but still this is the best we can do. However, I assume that forHeaderName
using&'static str
is the more common case.Use case
I have to use
format!
to build some complexHeaderValue
. So far, I have to usemy_value.as_str().into_header_value()
which internally uses.to_string()
, so it creates a new allocation for the string, and the old allocation gets just freed afterward. Maybe the compiler can optimize this allocation away, but maybe not...Contribution
Yes. Preparing PR.
The text was updated successfully, but these errors were encountered: