A client, represented by Rust’s Receiver, is the channel handle that obtains values sent by one or more matching Sender handles. A channel connects both handles to the same value type. section 12.5.1 section 12.5
Use the Receiver to:
- Call recv() to wait for the next value; it returns a Result and blocks while a Sender remains alive without sending. section 12.5.2
- Call try_recv() to check immediately instead of waiting; it can return before a value arrives. section 12.5.2
- Continue receiving queued values after a Sender is dropped, then receive an error when no senders or pending values remain. section 12.5.2
- Receive messages from several threads when cloned Senders send into the same channel. section 12.5.2
Receive one value
Create the pair, send an i32, and print what the client receives: let (sender, receiver) = channel(); sender.send(5).unwrap(); println!("{}", receiver.recv().unwrap()); The value 5 travels from the Sender to the Receiver. section 12.5.2
use std::sync::mpsc::channel;
fn main() {
let (sender, receiver) = channel();
sender.send(5).unwrap();
println!("{}", receiver.recv().unwrap());
}
Inspect the complete minimal channel example, including result handling and output from recv(). section 12.5.2














