diff --git a/cl-structures/src/intern_pool.rs b/cl-structures/src/intern_pool.rs index e94dadb..deffced 100644 --- a/cl-structures/src/intern_pool.rs +++ b/cl-structures/src/intern_pool.rs @@ -102,6 +102,12 @@ impl Pool { 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 { + (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);