-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Change iterator implementations to return borrowed keys #47
Comments
I don't mind. I can't remember why they're copy, so if you want to give it a stab, please document in case you come up against any problems. |
Looking at the way In the simple case, we could store the list of keys somewhere in the storage to get around this, with the trade-off of making EDIT: Oops. Pressed send slightly too early. |
Ah yeah. That's clearly also an issue for SetStorage, since for simple enums it's implemented as a boolean array. Or as a bitset if Tricky! I'm not sure how to construct compound keys like for |
For compound keys I was thinking of delegating the key storage to the innermost layer that each variant combination can reach. Though with long chains, that can risk massively bloating up the storage space of the innermost layer. |
Or: "Do the iterators really need to copy the keys by default?"
I'm having a bit of trouble creating an implementation for
bevy_reflect::Map
on a wrapper type around yourfixed_map::Map
type. The problem stems from the requirement thatbevy_reflect::Map::get_at
andbevy_reflect::Map::get_at_mut
return the key-value pairs as borroweddyn Reflect
trait objects. While this is easy for the values (since they are borrowed anyway), there comes a problem with the keys. Because the keys are given from youriter()
anditer_mut()
iterators as owned values, this makes it impossible to meet the requirement for the trait.Due to how trivial it is to acquire an owned key if necessary for a user's use-case (since the keys must implement
Copy
, simply doing*key
in the iterator adaptor is good enough), I propose that the iterator implementations instead return borrows of the keys and leave it to the user to copy them if necessary.The text was updated successfully, but these errors were encountered: