0
0
Rustprogramming~10 mins

Message passing concepts in Rust - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a channel for message passing.

Rust
let (tx, rx) = std::sync::mpsc::[1]();
Drag options to blanks, or click blank then click option'
Aspawn
Bsend
Crecv
Dchannel
Attempts:
3 left
💡 Hint
Common Mistakes
Using send or recv instead of channel to create the channel.
Trying to spawn a thread here instead of creating a channel.
2fill in blank
medium

Complete the code to send a message through the channel.

Rust
tx.[1](42).unwrap();
Drag options to blanks, or click blank then click option'
Asend
Brecv
Cclone
Dwait
Attempts:
3 left
💡 Hint
Common Mistakes
Using recv() on the sender side instead of send().
Trying to clone the sender instead of sending a message.
3fill in blank
hard

Fix the error in receiving a message from the channel.

Rust
let received = rx.[1]().unwrap();
Drag options to blanks, or click blank then click option'
Arecv
Bclone
Csend
Dwait
Attempts:
3 left
💡 Hint
Common Mistakes
Using send() on the receiver side instead of recv().
Trying to clone the receiver instead of receiving a message.
4fill in blank
hard

Fill both blanks to create a thread that sends a message.

Rust
std::thread::[1](move || {
    tx.[2]("hello").unwrap();
});
Drag options to blanks, or click blank then click option'
Aspawn
Bsend
Crecv
Djoin
Attempts:
3 left
💡 Hint
Common Mistakes
Using join() instead of spawn() to create a thread.
Using recv() instead of send() to send a message.
5fill in blank
hard

Fill all three blanks to receive and print a message.

Rust
let message = rx.[1]().unwrap();
println!("[2]: {}", [3]);
Drag options to blanks, or click blank then click option'
Asend
Bmessage
CReceived message
Drecv
Attempts:
3 left
💡 Hint
Common Mistakes
Using send() instead of recv() to receive the message.
Printing a wrong variable or string instead of the message.