Skip to content

Creating a &'static HeaderName #143

@zesterer

Description

@zesterer

Hi,

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions