Async Entity Component System based on the ideas of specs (https://github.com/amethyst/specs)
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

57 linhas
2.5 KiB

  1. use super::{Folder, Reducer};
  2. /// A consumer is effectively a [generalized "fold" operation][fold],
  3. /// and in fact each consumer will eventually be converted into a
  4. /// [`Folder`]. What makes a consumer special is that, like a
  5. /// [`Producer`], it can be **split** into multiple consumers using
  6. /// the `split_off_left` method. When a consumer is split, it produces two
  7. /// consumers, as well as a **reducer**. The two consumers can be fed
  8. /// items independently, and when they are done the reducer is used to
  9. /// combine their two results into one. See [the README][r] for further
  10. /// details.
  11. ///
  12. /// [r]: README.md
  13. /// [fold]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.fold
  14. /// [`Folder`]: trait.Folder.html
  15. /// [`Producer`]: trait.Producer.html
  16. pub trait Consumer<I>: Send + Sized {
  17. /// The type of folder that this consumer can be converted into.
  18. type Folder: Folder<I, Result = Self::Result>;
  19. /// The type of reducer that is produced if this consumer is split.
  20. type Reducer: Reducer<Self::Result>;
  21. /// The type of result that this consumer will ultimately produce.
  22. type Result: Send;
  23. /// Splits off a "left" consumer and returns it. The `self`
  24. /// consumer should then be used to consume the "right" portion of
  25. /// the data. (The ordering matters for methods like find_first --
  26. /// values produced by the returned value are given precedence
  27. /// over values produced by `self`.) Once the left and right
  28. /// halves have been fully consumed, you should reduce the results
  29. /// with the result of `to_reducer`.
  30. fn split_off_left(&self) -> (Self, Self::Reducer);
  31. /// Convert the consumer into a folder that can consume items
  32. /// sequentially, eventually producing a final result.
  33. fn into_folder(self) -> Self::Folder;
  34. /// Hint whether this `Consumer` would like to stop processing
  35. /// further items, e.g. if a search has been completed.
  36. fn is_full(&self) -> bool {
  37. false
  38. }
  39. }
  40. /// A stateless consumer can be freely copied. These consumers can be
  41. /// used like regular consumers, but they also support a
  42. /// `split_at` method that does take an index to split.
  43. pub trait IndexedConsumer<I>: Consumer<I> {
  44. /// Divide the consumer into two consumers, one processing items
  45. /// `0..index` and one processing items from `index..`. Also
  46. /// produces a reducer that can be used to reduce the results at
  47. /// the end.
  48. fn split_at(self, index: usize) -> (Self, Self, Self::Reducer);
  49. }