pumpkin_core/containers/
key_generator.rs

1use std::marker::PhantomData;
2
3use super::StorageKey;
4
5/// Generates a sequence of [`StorageKey`]s.
6#[derive(Clone, Copy, Debug)]
7pub struct KeyGenerator<Key> {
8    key: PhantomData<Key>,
9    counter: usize,
10}
11
12impl<Key> Default for KeyGenerator<Key> {
13    fn default() -> Self {
14        Self {
15            key: Default::default(),
16            counter: Default::default(),
17        }
18    }
19}
20
21impl<Key: StorageKey> KeyGenerator<Key> {
22    /// Generate a new `Key`.
23    pub fn next_key(&mut self) -> Key {
24        let key = Key::create_from_index(self.counter);
25        self.counter += 1;
26        key
27    }
28}