Async Entity Component System based on the ideas of specs (https://github.com/amethyst/specs)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.6 KiB

  1. use crate::core::{Consumer, Executor, Folder, IndexedProducer, Producer, Reducer};
  2. #[derive(Default)]
  3. pub struct Sequential;
  4. impl<'a, T1, T2, T3> Executor<'a, T1, T2, T3> for Sequential
  5. where
  6. T1: Send + 'a,
  7. T2: Send + 'a,
  8. T3: Send + 'a,
  9. {
  10. type Result = T1;
  11. type Inner = Sequential;
  12. fn exec<P, C, R>(self, producer: P, consumer: C) -> Self::Result
  13. where
  14. P: Producer + 'a,
  15. C: Consumer<P::Item, Result = T1, Reducer = R> + 'a,
  16. R: Reducer<T1>,
  17. {
  18. if consumer.is_full() {
  19. consumer.into_folder().complete()
  20. } else {
  21. producer.fold_with(consumer.into_folder()).complete()
  22. }
  23. }
  24. fn exec_indexed<P, C, R>(self, producer: P, consumer: C) -> Self::Result
  25. where
  26. P: IndexedProducer,
  27. C: Consumer<P::Item, Result = T1, Reducer = R>,
  28. R: Reducer<T1>,
  29. {
  30. if consumer.is_full() {
  31. consumer.into_folder().complete()
  32. } else {
  33. producer.fold_with(consumer.into_folder()).complete()
  34. }
  35. }
  36. fn ready(self, value: T1) -> Self::Result {
  37. value
  38. }
  39. fn split(self) -> (Self, Self) {
  40. (Self, Self)
  41. }
  42. fn join<R>(left: T1, right: T1, reducer: R) -> Self::Result
  43. where
  44. R: Reducer<T1> + Send,
  45. {
  46. reducer.reduce(left, right)
  47. }
  48. fn into_inner(self) -> Self::Inner {
  49. self
  50. }
  51. fn map<O>(
  52. inner: <Self::Inner as Executor<'a, T2, T3, ()>>::Result,
  53. mut operation: O,
  54. ) -> Self::Result
  55. where
  56. O: FnMut(T2) -> T1,
  57. {
  58. operation(inner)
  59. }
  60. }