Skip to content

Creating headers without creating Header structs #81

@gtolle

Description

@gtolle

As part of my little rest_client project, I'm interested in making it possible for the user to specify custom headers for a request using string tuples, like ("X-Modhash", "foobar").

I'm totally impressed with this typed header design, especially on the server side where you've defined a set of headers that you're willing to process.

But, I don't see a way for a client to set a new header into the Headers object without actually creating a new struct that implements the Header trait and defines the name of the header as a static string (e.g. "X-Modhash") returned by fn header_name.

This seems to make it impossible for a client to specify a new header at runtime without creating a new struct at compile-time.

I took a stab at using macros to do it, but my Rust knowledge hit a wall. So, I thought I'd ask.

How would you implement a custom header on the client side without requiring the user to write a ~16 line struct/impl definition for that header?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions