Skip to content

Multiple calls to vacant_entry / self referential entries. #55

@jpittis

Description

@jpittis

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.

Slab<(SomeValue, usize)>

So your the instance of your slab might contain something along the lines of this:

// slab[0] = (MyFirstValue, 1)
// slab[1] = (MySecondValue, 0)

There's currently no way to create two referencing entries inside a slab because we can't make multiple calls to vacant_entry.

let first_entry = slab.vacant_entry();
let second_entry = slab.vacant_entry();
// use the entry.key() from each vacant_entry to insert references to the other.

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions