#RustQuiz : What is the output?

A. Compilation error in X & Y

B. Runtime error in X & Y

C. X prints "boo" and "kernel", Y Prints "Kernel"

D. X gives compilation error, Y prints "Kernel"

vote below

#rustlang #rust

vote here
A. Compilation error in X & Y
8.3%
B. Runtime error in X & Y
0%
C. X prints "boo" and "kernel", Y Prints "Kernel"
83.3%
D. X gives compilation error, Y prints "Kernel"
8.3%
Poll ended at .

Answer: D. X gives compilation error, Y prints "Kernel"

"The task supplied to `spawn` must implement `Send`. However, it is
possible to **use** `!Send` values from the task as long as they only
exist between calls to `.await`."

I am still trying to find reason why X gives compilation error. The Y will work since it is get dropped before the next await (line 15)

------

I have attached few more example code snippets.
In this example, both e1 and e2 will work

In 1st, there is no await inside the spawn block so it allows

In 2nd, everything gets dropped before next await (which makes you doubt why Y in the quiz didn't work) and works

Reference:
https://docs.rs/tokio/latest/tokio/task/fn.spawn.html#using-send-values-from-a-task

spawn in tokio::task - Rust

Spawns a new asynchronous task, returning a `JoinHandle` for it.