pub struct ChannelReceiver<T> { /* private fields */ }
Expand description

The channel part that receives data. It is generic over the type of messages sent in the channel. The type of the messages must match between sender and receiver.

This type is not Clone since the channel is multiple producers, single consumer, just like std::sync::mpsc.

Implementations§

Receive a message from the channel. This method will block until the other end sends a message.

If the other end used send_raw this method panics since the channel corrupts.

let (sender, receiver) = new_local_channel();
sender.send(42);
let num: i32 = receiver.recv().unwrap();
assert_eq!(num, 42);

Receive some raw data from the channel. This method will block until the other end sends some data.

If the other end used send this method panics since the channel corrupts.

let (sender, receiver) = new_local_channel::<()>();
sender.send_raw(&vec![1, 2, 3]);
let data: Vec<u8> = receiver.recv_raw().unwrap();
assert_eq!(data, vec![1, 2, 3]);

Given this is a remote channel, change the type of the message. Will panic if this is a ChannelReceiver::Local.

This function is useful for implementing a protocol where the message types change during the execution, for example because initially there is an handshake message, followed by the actual protocol messages.

let receiver: ChannelReceiver<i32> = receiver.change_type();
let receiver: ChannelReceiver<String> = receiver.change_type();

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.