generational_token_list
A doubly-linked list backed by generational-arena. Inspired by indexlist.
Instead of returning pointers or numerical indices to items this data structure returns opaque ItemTokens.
Tokens remain valid regardless of other items being inserted or removed. Removing an item invalidates its token. Clearing the list invalidates all tokens.
More details and examples are available in the documentation for the methods.
Useful features
There are a couple features that I think make this crate stand out compared to other similar crates. Some crates implement a few of these features but I haven't found one that implements all of them (or at the very least, both 1 and 2).
- Insertion of items relative to other items
- All push/insert methods have a variant that takes a
FnOnceallowing creation of items that know their own token
- Passthrough of
get2_mutmethod from generational-arena. - Implements
IterandIterMuttraits.
Safety
The only usage of unsafe is in the implementation of iter_mut. I don't think there is any other way.
Similar crates
TODO
Pull requests are welcome :)
- Implement
IndexandIndexMuttraits - Implement
Drain - Implement
try_push_*andtry_insert_*methods - Implement flavors of
push_*_withandinsert_*_withthat allow fallible insertion of items? E.g.:
- Add
no-stdsupport?' - Consider adding
#[inline]to some methods?
Disclaimer
This is not an official Agilent product. No support is implied.