From 6dc79952db4be461dc7abaafed8601c8b86bb242 Mon Sep 17 00:00:00 2001 From: Aramis Razzaghipour Date: Fri, 15 Jan 2021 10:37:09 +1100 Subject: Add docs to la-arena crate --- lib/arena/src/map.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/arena/src/map.rs') diff --git a/lib/arena/src/map.rs b/lib/arena/src/map.rs index 0f33907c0..980198247 100644 --- a/lib/arena/src/map.rs +++ b/lib/arena/src/map.rs @@ -12,6 +12,7 @@ pub struct ArenaMap { } impl ArenaMap, V> { + /// Inserts a value associated with a given arena ID into the map. pub fn insert(&mut self, id: Idx, t: V) { let idx = Self::to_idx(id); @@ -19,22 +20,27 @@ impl ArenaMap, V> { self.v[idx] = Some(t); } + /// Returns a reference to the value associated with the provided ID if it is present. pub fn get(&self, id: Idx) -> Option<&V> { self.v.get(Self::to_idx(id)).and_then(|it| it.as_ref()) } + /// Returns a mutable reference to the value associated with the provided ID if it is present. pub fn get_mut(&mut self, id: Idx) -> Option<&mut V> { self.v.get_mut(Self::to_idx(id)).and_then(|it| it.as_mut()) } + /// Returns an iterator over the values in the map. pub fn values(&self) -> impl Iterator { self.v.iter().filter_map(|o| o.as_ref()) } + /// Returns an iterator over mutable references to the values in the map. pub fn values_mut(&mut self) -> impl Iterator { self.v.iter_mut().filter_map(|o| o.as_mut()) } + /// Returns an iterator over the arena IDs and values in the map. pub fn iter(&self) -> impl Iterator, &V)> { self.v.iter().enumerate().filter_map(|(idx, o)| Some((Self::from_idx(idx), o.as_ref()?))) } -- cgit v1.2.3