The Header trait requires a name function that returns a &'static HeaderName. However, none of the methods used to construct a HeaderName are marked const (and so cannot be used to create a regular static, either explicitly or via promotion of a local temporary), so there appears to only be two possible ways to write a valid implementation of Header::name:
1) Box and then leak a HeaderName on every call
2) Set up a lazy_static (or equivalent via new primitives like LazyCell) that uses internal mutability to lazily initiate a HeaderName
Both of these approaches are undesirable for fairly clear reasons, the first especially, which leads me to the question:
What is the intended approach when implementing this trait?
Or, alternatively, would it be possible to do one of the following?
1) Make some of the methods used to create `HeaderName` `const` (as is the case for `HeaderValue`)
2) Have `Header::name` return `Cow<'static, HeaderName>`
Hi,
The
Header
trait requires aname
function that returns a&'static HeaderName
. However, none of the methods used to construct aHeaderName
are markedconst
(and so cannot be used to create a regular static, either explicitly or via promotion of a local temporary), so there appears to only be two possible ways to write a valid implementation ofHeader::name
:1) Box and then leak a
HeaderName
on every call2) Set up a
lazy_static
(or equivalent via new primitives likeLazyCell
) that uses internal mutability to lazily initiate aHeaderName
Both of these approaches are undesirable for fairly clear reasons, the first especially, which leads me to the question:
What is the intended approach when implementing this trait?