-
Notifications
You must be signed in to change notification settings - Fork 84
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
Multiple calls to vacant_entry / self referential entries. #55
Comments
The only way to do this safely would be to have a way to get N vacant entries atomically. |
This could be implemented without allocating for the N entries by having an iterator that produce the keys that future It could be used as let (first, second) = {
let mut keys = slab.next_keys();
(keys.next().unwrap(), keys.next().unwrap())
};
slab.insert(second);
slab.insert(first); or let keys = slab.next_keys().take(4).collect::<Vec<usize>>();
for key in keys {
// ...
} I've implemented this here and can open a pull request if anybody is interested. |
@tormol Interesting thought. I'm a little uncomfortable with that strategy as can issue other operations on the slab that would invalidate the promised keys. For example, if you remove an entry before using a promised key, that changes things. |
Yes, after removing something then one will always get the wrong key, so any bug, if not immediately discovered, will at least be easy to reproduce. |
In general, I prefer opting for APIs that are hard (impossible) to misuse. |
TLDR: I want to be able to allocate multiple entries of a slab in a single go so I can have the entries reference each other.
Imagine you want to keep a value and a reference to another slab entry inside a slab.
So your the instance of your slab might contain something along the lines of this:
There's currently no way to create two referencing entries inside a slab because we can't make multiple calls to
vacant_entry
.The only way for me to accomplish something like this right now is to update the entries using
get_mut
with the correct keys once I've already inserted the values.Is this too a complex a feature request for this library?
Is there another, better way to do this?
The text was updated successfully, but these errors were encountered: