Async Entity Component System based on the ideas of specs (https://github.com/amethyst/specs)
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

66 wiersze
1.3 KiB

  1. use std::cmp::{min, Ord, Ordering};
  2. use crate::{Driver, Executor, ParallelIterator};
  3. /* Min */
  4. pub struct Min<X> {
  5. iterator: X,
  6. }
  7. impl<X> Min<X> {
  8. pub fn new(iterator: X) -> Self {
  9. Self { iterator }
  10. }
  11. }
  12. impl<'a, X, T> Driver<'a, Option<T>> for Min<X>
  13. where
  14. X: ParallelIterator<'a, Item = T>,
  15. T: Send + Ord + 'a,
  16. {
  17. fn exec_with<E>(self, executor: E) -> E::Result
  18. where
  19. E: Executor<'a, Option<T>>,
  20. {
  21. self.iterator.reduce_with(min).exec_with(executor)
  22. }
  23. }
  24. /* MinBy */
  25. pub struct MinBy<X, O> {
  26. iterator: X,
  27. operation: O,
  28. }
  29. impl<X, O> MinBy<X, O> {
  30. pub fn new(iterator: X, operation: O) -> Self {
  31. Self {
  32. iterator,
  33. operation,
  34. }
  35. }
  36. }
  37. impl<'a, X, O, T> Driver<'a, Option<T>> for MinBy<X, O>
  38. where
  39. X: ParallelIterator<'a, Item = T>,
  40. O: Fn(&T, &T) -> Ordering + Clone + Send + Sync + 'a,
  41. T: Send + Ord + 'a,
  42. {
  43. fn exec_with<E>(self, executor: E) -> E::Result
  44. where
  45. E: Executor<'a, Option<T>>,
  46. {
  47. let operation = self.operation;
  48. self.iterator
  49. .reduce_with(move |a, b| match operation(&a, &b) {
  50. Ordering::Greater => b,
  51. _ => a,
  52. })
  53. .exec_with(executor)
  54. }
  55. }