-
-
Notifications
You must be signed in to change notification settings - Fork 343
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 #299