Container Iterator
SOF3 opened this issue · 4 comments
There is no way to list all values from Container.
Getting an iterator is probably not very useful since values have distinct types. What I really need is to have a way to debug-print the Container.
There's no way to implement this safely unless we add a Debug
bound to all set
methods. I'm not sure the trade-off is worth it. This is reminiscent of #3 where what we'd really like is to have some sort of polymorphic trait bounds. In some pseudo-Rust, we might write:
struct Container<bounds B>(...);
impl<bounds B> Container<B> {
fn set<T: B>(value: T) { /* here we know `T: B`, even if we erase the type */ }
}
impl<bounds B: Debug> Debug for Container<B> {
/* now we can make use of the fact that all erased `T`s implement `Debug` */
}
Alas, this does not exist in Rust. The alternative is to have different versions of Container
with different bounds, or to have a macro that somehow safely generates a definition for Container
.
What is missing in Rust here?
I've come up with a mechanism to make something ~like this work, albeit not fully generically. If you or anyone would like to implement variants of Container
with Debug
bounds, feel free to do so.
Container
now implements a very basic Debug
. I think this is as good as it gets, given all of the type erasure.