Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The function std::sync::mpsc::channel() creates a new channel for message passing.
2fill in blank
mediumComplete the code to send a message through the channel.
Rust
tx.[1](42).unwrap();
Drag options to blanks, or click blank then click option'
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.
✗ Incorrect
The send() method is used on the transmitter to send a message through the channel.
3fill in blank
hardFix 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'
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.
✗ Incorrect
The recv() method is used on the receiver to receive a message from the channel.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using join() instead of spawn() to create a thread.
Using recv() instead of send() to send a message.
✗ Incorrect
Use spawn() to create a new thread and send() to send a message inside it.
5fill in blank
hardFill 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'
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.
✗ Incorrect
Use recv() to get the message, then print it with the variable holding the message.