[][src]Struct ductile::ChannelSender

pub struct ChannelSender<T> { /* fields omitted */ }

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.

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

Implementations

impl<T> ChannelSender<T> where
    T: 'static + Send + Sync + Serialize
[src]

pub fn send(&self, data: T) -> Result<()>[src]

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());

pub fn send_raw(&self, data: &[u8]) -> Result<()>[src]

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());

pub fn change_type<T2>(self) -> ChannelSender<T2>[src]

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

impl<T: Clone> Clone for ChannelSender<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for ChannelSender<T>

impl<T> Send for ChannelSender<T> where
    T: Send

impl<T> Sync for ChannelSender<T> where
    T: Send

impl<T> Unpin for ChannelSender<T>

impl<T> UnwindSafe for ChannelSender<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,