Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Add generics in Index #35

Open
mikialex opened this issue Jun 11, 2020 · 4 comments
Open

Add generics in Index #35

mikialex opened this issue Jun 11, 2020 · 4 comments

Comments

@mikialex
Copy link

mikialex commented Jun 11, 2020

Index returned from Arena<TypeA> should not be used in Arena<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: Arena insert item and return Index.

some 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.

@sinistersnare
Copy link

Hi, I would also like that for a project of mine. Would this change be welcome?

@Prin-to
Copy link

Prin-to commented Oct 13, 2020

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 :)

@AaronKutch
Copy link

PhatomData is included in core

@LoganDark
Copy link

LoganDark commented Nov 5, 2023

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 (markcsaving/drop_arena#1). However, an Index generic over the value type could still be useful for structs that contain Indexes to multiple arenas, because then it would at least be obvious which Index goes to which arena.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants