Card 1 / 4
Write an async fn that returns the sum of its two arguments. block_on is a minimal executor the exercise provides above your code: it polls a future on the current thread until it is ready, then returns that value.
a |
b |
block_on(add(a, b)) |
|---|---|---|
2 |
3 |
5 |
-1 |
1 |
0 |
An async fn does not return its declared type directly โ async fn add(a: i32, b: i32) -> i32 desugars to a function returning a Future whose Output is i32, and none of the body runs until something polls it. The body itself is ordinary code.
/// Write an async function that returns `a + b`.
async fn add(a: i32, b: i32) -> i32 {
a + b
}Card 2 / 4
double is given. Write quad so that awaiting it yields the input times four. block_on, provided above your code, is a minimal executor that polls a future to completion and returns its value.