Open mikialex opened 4 years ago
Hi, I would also like that for a project of mine. Would this change be welcome?
Hello, making the Index generic will probably bind it to the std
, which against the aim of this repo.
You can easily clone the repo and change the Index class into
use std::marker::PhantomData struct Index<T> { index: u64, generation : usize, phantom: PhantomData<T> }
I hope it helped you :)
PhatomData
is included in core
In order to properly enforce this, it would require an invariant lifetime like drop_arena
, which would make it incredibly painful to include an Arena
as a field in any other structure (https://github.com/markcsaving/drop_arena/issues/1). However, an Index
generic over the value type could still be useful for structs that contain Index
es to multiple arenas, because then it would at least be obvious which Index
goes to which arena.
Index returned from insert item and return Index.
Arena<TypeA>
should not be used inArena<TypeB>
, but we dont use generics in index, so such type constraint not exist. To enforce compiletime check better we can add generics in index: Arenasome reference https://github.com/gfx-rs/naga/blob/master/src/arena.rs (without generation check)
When using generational-arena to store different type of resource, like scenegraph resource management, such typed Index handle is essential.