diff --git a/src/protocol/arena.rs b/src/protocol/arena.rs index 21d3af16ee6ec5a2cdc65fe2bafd7f0019acba0e..c2e9ed75708ea1a3c05c1fdd8940e3ab952a9b7d 100644 --- a/src/protocol/arena.rs +++ b/src/protocol/arena.rs @@ -7,6 +7,13 @@ pub struct Id { pub(crate) index: u32, _phantom: PhantomData, } + +impl Id { + pub(crate) fn new(index: u32) -> Self { + Self{ index, _phantom: Default::default() } + } +} + #[derive(Debug, serde::Serialize, serde::Deserialize)] pub(crate) struct Arena { store: Vec, @@ -42,19 +49,13 @@ impl Arena { } pub fn alloc_with_id(&mut self, f: impl FnOnce(Id) -> T) -> Id { use std::convert::TryFrom; - let id = Id { - index: u32::try_from(self.store.len()).expect("Out of capacity!"), - _phantom: Default::default(), - }; + let id = Id::new(u32::try_from(self.store.len()).expect("Out of capacity!")); self.store.push(f(id)); id } pub fn iter(&self) -> impl Iterator { self.store.iter() } - pub fn iter_mut(&mut self) -> impl Iterator { - self.store.iter_mut() - } pub fn len(&self) -> usize { self.store.len() }