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.

95 linhas
2.1 KiB

  1. pub mod chain;
  2. pub mod cloned;
  3. pub mod collect;
  4. pub mod copied;
  5. pub mod count;
  6. pub mod filter;
  7. pub mod filter_map;
  8. pub mod find;
  9. pub mod flatten;
  10. pub mod fold;
  11. pub mod for_each;
  12. pub mod inspect;
  13. pub mod map;
  14. pub mod map_init;
  15. pub mod map_with;
  16. pub mod max;
  17. pub mod min;
  18. pub mod noop;
  19. pub mod panic_fuse;
  20. pub mod product;
  21. pub mod reduce;
  22. pub mod sum;
  23. pub mod try_fold;
  24. pub mod try_for_each;
  25. pub mod try_reduce;
  26. pub mod update;
  27. pub mod while_some;
  28. #[cfg(test)]
  29. mod tests {
  30. use crate::*;
  31. #[tokio::test]
  32. async fn test_for_each() {
  33. use ::std::sync::atomic::{AtomicUsize, Ordering};
  34. use ::std::sync::Arc;
  35. let i = Arc::new(AtomicUsize::new(0));
  36. let j = Arc::new(AtomicUsize::new(0));
  37. let a = vec![
  38. vec![1usize, 2usize],
  39. vec![3usize, 4usize],
  40. vec![5usize, 6usize],
  41. ];
  42. let b = vec![
  43. vec![7usize, 8usize],
  44. vec![9usize, 10usize],
  45. vec![11usize, 12usize],
  46. ];
  47. let x = a
  48. .par_iter()
  49. .cloned()
  50. .chain(b)
  51. .update(|x| x.push(0))
  52. .flatten_iter()
  53. .panic_fuse()
  54. .map(Some)
  55. .while_some()
  56. .map_init(
  57. move || i.fetch_add(1, Ordering::Relaxed),
  58. |init, item| Some((item, *init)),
  59. )
  60. .try_fold_with(String::new(), |s, item| -> Result<String, ()> {
  61. Ok(format!("{} + {:?}", s, item))
  62. })
  63. .try_for_each_init(
  64. move || j.fetch_add(1, Ordering::Relaxed),
  65. |init, item| -> Result<(), ()> {
  66. println!("{:?} - {:?}", init, item);
  67. Ok(())
  68. },
  69. )
  70. .exec()
  71. .await;
  72. dbg!(&x);
  73. }
  74. #[tokio::test]
  75. async fn test_reduce() {
  76. let x = (0..10usize)
  77. .into_par_iter()
  78. .map::<_, Result<usize, ()>>(Ok)
  79. .try_reduce(|| 0, |a, b| Ok(a + b))
  80. .exec()
  81. .await;
  82. dbg!(&x);
  83. assert_eq!(Ok(45), x);
  84. }
  85. }