Closed AndreaCatania closed 5 years ago
Hello @fitzgen do you like to add such a change or it's not something that you like to support?
It isn't clear to me what the use case / motivation is here or why the proposed solution is the best way to solve the problem. Could you provide more details?
I'm implementing the APIs of an interface that use opaque ids to refer the elements. This opaque ids is called ResourceID
.
fn create_element() -> ResoourceID;
fn drop_element(id: ResourceID);
fn set_color(id: ResourceID, color: Vec<f32>);
Internally I'm storing the elements inside the generational arena, and I need to convert the Index
from/to the ResourceID
.
I've added this possibility with the PR https://github.com/fitzgen/generational-arena/pull/22 and would be nice if this could land upstream.
Make the Index opaque is something really useful that even other similar libraries already support.
So you don't want this to actually allocate space for the index or anything like that?
It seems like the APIs you are describing are possible with a new type right now:
struct ResourceId(Index);
What am I missing here?
ResourceId
is a type defined by the abstraction that I cannot change. Check it here: https://github.com/AndreaCatania/amethyst_phythyst/blob/master/src/objects.rs#L12-L74
@fitzgen also there is a fork of your crate (that for sure you know https://crates.io/crates/typed-generational-arena) that allow me do what I need. But I would like to use directly your crate since I don't really need a new type.
By the way, other crates like slotmap
allows to obtains an opaque ID: https://github.com/orlp/slotmap/blob/master/src/lib.rs#L298 This solution is a bit restrictive but would be also enough for me.
My proposal to add this feature is this one: https://github.com/fitzgen/generational-arena/pull/22/files
I need to create an opaque key.
Would be nice to have the possibility to use a function new to create an
Index
, when you want to deal with opaque indices.It's unsafe crate IDs out of this crate, so an idea is to create an
unsafe
function. Something like:unsafe create(id: u32, version: u32);