cl-structures: Add helper for getting index from pool. May delete later.

This commit is contained in:
John 2024-04-16 23:48:05 -05:00
parent 0e8b4f68c3
commit ec1a1255ad

View File

@ -102,6 +102,12 @@ impl<T, ID: InternKey> Pool<T, ID> {
unsafe { InternKeyIter::new(0..self.pool.len()) }
}
/// Constructs an [ID](InternKey) from a [usize], if it's within bounds
#[doc(hidden)]
pub fn try_key_from(&self, value: usize) -> Option<ID> {
(value < self.pool.len()).then(|| unsafe { ID::from_raw_unchecked(value) })
}
pub fn insert(&mut self, value: T) -> ID {
let id = self.pool.len();
self.pool.push(value);