From 2dfbd9ae92c139e306afc87994adac82489f30eb Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Fri, 30 Apr 2021 11:37:58 +0200 Subject: Add comments. --- src/data/component_set.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/data/component_set.rs') diff --git a/src/data/component_set.rs b/src/data/component_set.rs index ca7df67..6e0461c 100644 --- a/src/data/component_set.rs +++ b/src/data/component_set.rs @@ -5,30 +5,47 @@ use crate::data::Index; // fn get(&self, handle: Index) -> Option<&T>; // } +/// A set of optional elements of type `T`. pub trait ComponentSetOption: Sync { + /// Get the element associated to the given `handle`, if there is one. fn get(&self, handle: Index) -> Option<&T>; } +/// A set of elements of type `T`. pub trait ComponentSet: ComponentSetOption { + /// The estimated number of elements in this set. + /// + /// This value is typically used for preallocating some arrays for + /// better performances. fn size_hint(&self) -> usize; // TODO ECS: remove this, its only needed by the query pipeline update // which should only take the modified colliders into account. + /// Iterate through all the elements on this set. fn for_each(&self, f: impl FnMut(Index, &T)); + /// Get the element associated to the given `handle`. fn index(&self, handle: Index) -> &T { self.get(handle).unwrap() } } +/// A set of mutable elements of type `T`. pub trait ComponentSetMut: ComponentSet { + /// Applies the given closure to the element associated to the given `handle`. + /// + /// Return `None` if the element doesn't exist. fn map_mut_internal( &mut self, handle: crate::data::Index, f: impl FnOnce(&mut T) -> Result, ) -> Option; + + /// Set the value of this element. fn set_internal(&mut self, handle: crate::data::Index, val: T); } +/// Helper trait to address multiple elements at once. pub trait BundleSet<'a, T> { + /// Access multiple elements from this set. fn index_bundle(&'a self, handle: Index) -> T; } -- cgit