mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-09-28 17:53:28 +00:00
move input files into exercise directory
This commit is contained in:
committed by
Mo Bitar
parent
b50eafb28f
commit
d0109d68be
@@ -6,14 +6,18 @@
|
||||
// Let's simulate this using asynchronous programming. Each person is
|
||||
// represented as an asynchronous task, which can be executed concurrently.
|
||||
|
||||
const SCORES_CLASS_A: &str = "exercises/24_async/scores_class_a.txt";
|
||||
const SCORES_CLASS_B: &str = "exercises/24_async/scores_class_b.txt";
|
||||
const SCORES_CLASS_C: &str = "exercises/24_async/scores_class_c.txt";
|
||||
|
||||
// Async tasks need to be executed by a "runtime", which is not provided by
|
||||
// Rust's standard library. Here, we use the mainstream runtime `tokio`.
|
||||
// The macro `tokio::main` wraps the entire main function in a runtime.
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let mean_score_a = tokio::spawn(calculate_mean_score("input_files/scores_class_a.txt"));
|
||||
let mean_score_b = tokio::spawn(calculate_mean_score("input_files/scores_class_b.txt"));
|
||||
let mean_score_c = tokio::spawn(calculate_mean_score("input_files/scores_class_c.txt"));
|
||||
let mean_score_a = tokio::spawn(calculate_mean_score(SCORES_CLASS_A));
|
||||
let mean_score_b = tokio::spawn(calculate_mean_score(SCORES_CLASS_B));
|
||||
let mean_score_c = tokio::spawn(calculate_mean_score(SCORES_CLASS_C));
|
||||
|
||||
assert_eq!(mean_score_a.await.unwrap(), 84); // alice
|
||||
assert_eq!(mean_score_b.await.unwrap(), 89); // bob
|
||||
|
||||
Reference in New Issue
Block a user