From ec1a1255ad5c5290c2facf3ca51c865f44c9c79b Mon Sep 17 00:00:00 2001 From: John Date: Tue, 16 Apr 2024 23:48:05 -0500 Subject: [PATCH] cl-structures: Add helper for getting index from pool. May delete later. --- cl-structures/src/intern_pool.rs | 6 ++++++ 1 file changed, 6 insertions(+) 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);