Struct SyncSender
struct SyncSender<T> { ... }
The sending-half of Rust's synchronous sync_channel type.
Messages can be sent through this channel with send or try_send.
send will block if there is no space in the internal buffer.
Examples
use sync_channel;
use thread;
// Create a sync_channel with buffer size 2
let = sync_channel;
let sync_sender2 = sync_sender.clone;
// First thread owns sync_sender
spawn;
// Second thread owns sync_sender2
spawn;
let mut msg;
msg = receiver.recv.unwrap;
println!;
// "Thread unblocked!" will be printed now
msg = receiver.recv.unwrap;
println!;
msg = receiver.recv.unwrap;
println!;
Implementations
impl<T> SyncSender<T>
fn send(self: &Self, t: T) -> Result<(), SendError<T>>Sends a value on this synchronous channel.
This function will block until space in the internal buffer becomes available or a receiver is available to hand off the message to.
Note that a successful send does not guarantee that the receiver will ever see the data if there is a buffer on this channel. Items may be enqueued in the internal buffer for the receiver to receive at a later time. If the buffer size is 0, however, the channel becomes a rendezvous channel and it guarantees that the receiver has indeed received the data if this function returns success.
This function will never panic, but it may return
Errif theReceiverhas disconnected and is no longer able to receive information.Examples
use sync_channel; use thread; // Create a rendezvous sync_channel with buffer size 0 let = sync_channel; spawn; let msg = receiver.recv.unwrap; assert_eq!;fn try_send(self: &Self, t: T) -> Result<(), TrySendError<T>>Attempts to send a value on this channel without blocking.
This method differs from
sendby returning immediately if the channel's buffer is full or no receiver is waiting to acquire some data. Compared withsend, this function has two failure cases instead of one (one for disconnection, one for a full buffer).See
sendfor notes about guarantees of whether the receiver has received the data or not if this function is successful.Examples
use sync_channel; use thread; // Create a sync_channel with buffer size 1 let = sync_channel; let sync_sender2 = sync_sender.clone; // First thread owns sync_sender let handle1 = spawn; // Second thread owns sync_sender2 let handle2 = spawn; let mut msg; msg = receiver.recv.unwrap; println!; msg = receiver.recv.unwrap; println!; // Third message may have never been sent match receiver.try_recv // Wait for threads to complete handle1.join.unwrap; handle2.join.unwrap;
impl<T> Any for SyncSender<T>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for SyncSender<T>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for SyncSender<T>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> Clone for SyncSender<T>
fn clone(self: &Self) -> SyncSender<T>
impl<T> CloneToUninit for SyncSender<T>
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> Debug for SyncSender<T>
fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> fmt::Result
impl<T> Freeze for SyncSender<T>
impl<T> From for SyncSender<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> RefUnwindSafe for SyncSender<T>
impl<T> Sync for SyncSender<T>
impl<T> ToOwned for SyncSender<T>
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> Unpin for SyncSender<T>
impl<T> UnwindSafe for SyncSender<T>
impl<T, U> Into for SyncSender<T>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for SyncSender<T>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for SyncSender<T>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>