hyperium / hyperium/http

Api to consume Extensions and import/export all items

Open
#780 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.4k
Forks
378
Avg merge
1d 21h
Merged PRs (30d)
5

Description

When traversing boundaries it's currently quite hard (nearly impossible) to extract all extensions and transfer them to somewhere else. There are some creative ways to work around this, like inserting a nested typemap into extensions, but these are all quite hacky.

Would you be open into some sort of api that can consume extensions and return the individual items, and then later add these back to a new or existing Extension object?

A very quick solution could be something like

impl IntoIterator for Extensions {
    type Item = (TypeId, Box<dyn AnyClone + Send + Sync>);
    type IntoIter = std::vec::IntoIter<Self::Item>;

    fn into_iter(self) -> Self::IntoIter {
        match self.map {
            None => Default::default(),
            Some(map) => {
                map.into_iter().collect::<Vec<_>>().into_iter()
            }
        }
        
    }
}

But it could be anything else, only requirement would be the functionality to export all items from extensions and import them back again. The example implementation also hides away the usage of a hashmap so this detail could be changed in the future if needed. But it does require AnyClone to be public (can be sealed). Please don't focus on this solution too much as I haven't really given it much thought, it's just here as an example / starting point.

I'm really open to all suggestions here on how to support this or what other solutions there might be available. Having extensions be interoperable with other type maps would be really useful and would make extensions much more flexible.

This is slightly related to https://github.com/hyperium/http/issues/299

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the Extensions and AnyClone types, then review the related issue #299 and the proposed IntoIterator example. Compare possible APIs for exporting all extension items and importing them into a new or existing Extensions object. Done means the project has an agreed, usable interoperability API rather than relying on nested typemap workarounds.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.