[−][src]Struct ductile::ChannelSender
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]
T: 'static + Send + Sync + Serialize,
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]
fn clone(&self) -> ChannelSender<T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for ChannelSender<T>
impl<T> Send for ChannelSender<T> where
T: Send,
T: Send,
impl<T> Sync for ChannelSender<T> where
T: Send,
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,