Struct ductile::ChannelSender

source ·
pub struct ChannelSender<T> { /* private fields */ }
Expand description

The channel part that sends data. It is generic over the type of messages sent and abstracts the underlying type of connection. The connection type can be local in memory, or remote using TCP sockets or local with Unix sockets.

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

Implementations§

Serialize and send a message in the channel. The message is not actually serialized for local channels, but the type must be Send + Sync.

For remote channel the message is serialized, if you want to send raw data (i.e. [u8]) that not need to be serialized consider using send_raw since its performance is way better.

This method is guaranteed to fail if the receiver is dropped only for local channels. Using remote channels drops this requirement.

let (sender, receiver) = new_local_channel();
sender.send(42u8).unwrap();
drop(receiver);
assert!(sender.send(69u8).is_err());

Send some raw data in the channel without serializing it. This is possible only for raw unstructured data ([u8]), but this methods is much faster than send since it avoids serializing the message.

This method is guaranteed to fail if the receiver is dropped only for local channels. Using remote channels drops this requirement.

let (sender, receiver) = new_local_channel::<()>();
sender.send_raw(&vec![1, 2, 3, 4]).unwrap();
drop(receiver);
assert!(sender.send_raw(&vec![1, 2]).is_err());

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

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 sender: ChannelSender<i32> = sender.change_type();
let sender: ChannelSender<String> = sender.change_type();

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

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 resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
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.