| Crates.io | generational_token_list |
| lib.rs | generational_token_list |
| version | 0.1.5 |
| created_at | 2021-11-27 16:52:24.255775+00 |
| updated_at | 2022-05-24 17:54:23.328186+00 |
| description | A doubly-linked list backed by generational-arena. |
| homepage | https://github.com/Agilent/generational_token_list |
| repository | https://github.com/Agilent/generational_token_list |
| max_upload_size | |
| id | 488470 |
| size | 51,732 |
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.
fn main() {
let mut list = GenerationalTokenList::<i32>::new();
let item1 = list.push_back(10);
let item2 = list.push_back(20);
let item3 = list.push_back(30);
let data = list.into_iter().collect::<Vec<_>>();
assert_eq!(data, vec![10, 20, 30]);
}
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.
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).
fn main() {
let mut list = GenerationalTokenList::<i32>::new();
let item1 = list.push_back(10);
list.push_back(20);
list.insert_after(item1, 300);
// list: [10, 300, 20]
}
FnOnce allowing creation of items that know their own tokenfn main() {
struct Meta {
data: u8,
my_token: ItemToken,
}
let mut list = GenerationalTokenList::new();
let item1 = list.push_back_with(|token| Meta { data: 1, my_token: token });
let item2 = list.push_back_with(|token| Meta { data: 2, my_token: token });
let item1_data = list.head().unwrap();
assert_eq!(item1, item1_data.my_token);
}
get2_mut method from generational-arena.Iter and IterMut1 traits.1 requires enabling iter-mut feature
iter-mut: enables the iter_mut method. See "Safety" section for more details.By default, this crate is forbid(unsafe_code).
If you need GenerationalTokenList::iter_mut and/or GenerationalTokenList::iter_with_tokens_mut then you must enable the iter-mut feature. Doing so makes the crate deny(unsafe_code), and the unsafe block inside iter_mut is excluded via allow(unsafe_code).
Pull requests are welcome :)
Draintry_push_* and try_insert_* methodspush_*_with and insert_*_with that allow fallible insertion of items? E.g.:pub fn push_back_fallible(&mut self, create: impl FnOnce(ItemToken) -> Result<T>) -> Result<ItemToken> {
//...
}
no-std support?'#[inline] to some methods?This is not an official Agilent product. No support is implied.