WIP HeaderValue: make Cow<'static, str>#335
Conversation
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`.
| #[derive(Clone, Eq, PartialEq, Hash)] | ||
| pub struct HeaderValue { | ||
| inner: String, | ||
| inner: Cow<'static, str>, |
There was a problem hiding this comment.
why not pub struct HeaderValue<'a> { inner: Cow<'a, str> } and just use HeaderValue<'static> where we need it to be 'static?
There was a problem hiding this comment.
@jbr That'd make the API a little more awkward to use, and would potentially be a backwards-compatibility issue.
|
Most header names (and many header values) will be short; we might want to use something like |
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 |
This allows HeaderValue to borrow
'staticstrings, rather than make allocations.Unfortunately, we can't specialize
TryFromorFrom, so this also adds a new crate-onlyfrom_static_str() -> HeaderValue.