diff options
Diffstat (limited to 'engine-ecs/src/util.rs')
| -rw-r--r-- | engine-ecs/src/util.rs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/engine-ecs/src/util.rs b/engine-ecs/src/util.rs index f56a5c4..c52608a 100644 --- a/engine-ecs/src/util.rs +++ b/engine-ecs/src/util.rs @@ -34,6 +34,23 @@ impl<Item> VecExt<Item> for Vec<Item> } } +impl<Item, const CAPACITY: usize> VecExt<Item> for ArrayVec<Item, CAPACITY> +{ + fn insert_at_part_pt_by_key<Key>( + &mut self, + item: Item, + mut func: impl FnMut(&Item) -> &Key, + ) where + Key: Ord, + { + let key = func(&item); + + let insert_index = self.partition_point(|other_item| func(other_item) <= key); + + self.insert(insert_index, item); + } +} + pub trait StreamingIterator { type Item<'a> @@ -190,9 +207,16 @@ pub trait Array<Item>: + Sortable<Item = Item> + sealed::Sealed { + fn map<T>(self, func: impl FnMut(Item) -> T) -> impl Array<T>; } -impl<Item, const CNT: usize> Array<Item> for [Item; CNT] {} +impl<Item, const CNT: usize> Array<Item> for [Item; CNT] +{ + fn map<T>(self, func: impl FnMut(Item) -> T) -> impl Array<T> + { + self.map(func) + } +} impl<Item, const CNT: usize> sealed::Sealed for [Item; CNT] {} @@ -414,6 +438,8 @@ macro_rules! const_assert { pub(crate) use const_assert; +use crate::util::array_vec::ArrayVec; + mod sealed { pub trait Sealed {} |
