summaryrefslogtreecommitdiff
path: root/ecs/src/util.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src/util.rs')
-rw-r--r--ecs/src/util.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/ecs/src/util.rs b/ecs/src/util.rs
new file mode 100644
index 0000000..f4f8632
--- /dev/null
+++ b/ecs/src/util.rs
@@ -0,0 +1,48 @@
+pub trait Sortable
+{
+ type Item;
+
+ fn sort_by_key_b<Key, Func>(&mut self, func: Func)
+ where
+ Func: FnMut(&Self::Item) -> Key,
+ Key: Ord;
+}
+
+impl<Item> Sortable for [Item]
+{
+ type Item = Item;
+
+ fn sort_by_key_b<Key, Func>(&mut self, func: Func)
+ where
+ Func: FnMut(&Self::Item) -> Key,
+ Key: Ord,
+ {
+ self.sort_by_key(func)
+ }
+}
+
+impl<Item, const LENGTH: usize> Sortable for [Item; LENGTH]
+{
+ type Item = Item;
+
+ fn sort_by_key_b<Key, Func>(&mut self, func: Func)
+ where
+ Func: FnMut(&Self::Item) -> Key,
+ Key: Ord,
+ {
+ self.sort_by_key(func)
+ }
+}
+
+impl<Item> Sortable for Vec<Item>
+{
+ type Item = Item;
+
+ fn sort_by_key_b<Key, Func>(&mut self, func: Func)
+ where
+ Func: FnMut(&Self::Item) -> Key,
+ Key: Ord,
+ {
+ self.sort_by_key(func)
+ }
+}