2 个版本
0.1.2 | 2022年12月11日 |
---|---|
0.1.1 | 2022年11月18日 |
0.1.0 |
|
在 异步 中排名第 843
10KB
144 代码行
一个用于竞速 Future
并返回排名结果 back 的 crate。
示例
use tokio::time::sleep;
use std::time::Duration;
use speedracer::RaceTrack;
let mut race_track = RaceTrack::disqualify_after(Duration::from_millis(500));
race_track.add_racer("Racer #1", async move {
println!("Racer #1 is starting");
sleep(std::time::Duration::from_millis(100)).await;
println!("Racer #1 is ending");
Ok(())
});
race_track.add_racer("Racer #2", async move {
println!("Racer #2 is starting");
sleep(std::time::Duration::from_secs(200)).await;
println!("Racer #2 is ending");
Ok(())
});
race_track.add_racer("Racer #3", async move {
println!("Racer #3 is starting");
sleep(std::time::Duration::from_secs(700)).await;
println!("Racer #3 is ending");
Ok(())
});
race_track.run().await;
let rankings = race_track.rankings();
println!("Rankings: {:?}", rankings);
assert_eq!(rankings[0].name, "Racer #1");
assert_eq!(rankings[1].name, "Racer #2");
assert_eq!(rankings[2].name, "Racer #3");
assert_eq!(rankings[2].disqualified, true);
依赖
~2.8–4MB
~64K SLoC