1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2025-11-29 22:47:43 +02:00

feat: add async exercises

This commit is contained in:
liv
2025-05-16 15:41:59 +02:00
parent e73fff3bd4
commit b2b3005670
35 changed files with 268 additions and 36 deletions

View File

@@ -0,0 +1,44 @@
// Our loyal worker works hard to create a new number.
#[derive(Default)]
struct Worker;
struct NumberContainer {
number: i32,
}
impl Worker {
async fn work(&self) -> NumberContainer {
// Pretend this takes a while...
let new_number = 32;
NumberContainer { number: new_number }
}
}
impl NumberContainer {
async fn extract_number(&self) -> i32 {
// And this too...
self.number
}
}
// TODO: Fix the function signature!
fn run_worker() -> i32 {
// TODO: Make our worker create a new number and return it.
}
fn main() {
// Feel free to experiment here. You may need to make some adjustments
// to this function, though.
}
mod tests {
use super::*;
// Don't worry about this attribute for now.
// If you want to know what this does, read the hint!
#[tokio::test]
async fn test_if_it_works() {
let number = run_worker().await;
assert_eq!(number, 32);
}
}