Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP HeaderValue: make Cow<'static, str> #335

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Fishrock123
Copy link
Member

This allows HeaderValue to borrow 'static strings, rather than make allocations.

Unfortunately, we can't specialize TryFrom or From, so this also adds a new crate-only from_static_str() -> HeaderValue.

This allows HeaderValue to borrow `'static` strings, rather than make allocations.

Unfortunately, we can't specialize `TryFrom` or `From`, so this also adds a new crate-only `from_static_str() -> HeaderValue`.
@Fishrock123 Fishrock123 added the semver-major This change requires a semver major change label Feb 23, 2021
@yoshuawuyts yoshuawuyts mentioned this pull request Feb 23, 2021
@@ -11,7 +12,7 @@ use crate::Mime;
/// A header value.
#[derive(Clone, Eq, PartialEq, Hash)]
pub struct HeaderValue {
inner: String,
inner: Cow<'static, str>,
Copy link
Member

@jbr jbr Apr 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not pub struct HeaderValue<'a> { inner: Cow<'a, str> } and just use HeaderValue<'static> where we need it to be 'static?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbr That'd make the API a little more awkward to use, and would potentially be a backwards-compatibility issue.

@joshtriplett
Copy link
Member

Most header names (and many header values) will be short; we might want to use something like kstring here, with a small-string optimization. kstring also supports Cow.

@jbr
Copy link
Member

jbr commented Jun 20, 2022

Most header names (and many header values) will be short; we might want to use something like kstring here, with a small-string optimization. kstring also supports Cow.

trillium's header name implementation does something like this, using smartcow which is just a cow for smartstring. However it might also make sense to use some sort of string interning library because there are only a handful of header names used in reality and they're repeated across requests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-major This change requires a semver major change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants