Struct SyncSender
pub struct SyncSender<T> { pub(in ::sync::mpsc) inner: Sender<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!;
Fields
inner: Sender<T>
Implementations
impl<T> SyncSender<T>
fn send(&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, 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;fn send_timeout(&self, t: T, timeout: Duration) -> Result<(), SendTimeoutError<T>>
Trait Implementations
impl<T> Clone for SyncSender<T>
fn clone(&self) -> SyncSender<T>
impl<T> Debug for SyncSender<T>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<T> Share for SyncSender<T>
impl<T: Send> Send for SyncSender<T>
Auto Trait Implementations
impl<T> Freeze for SyncSender<T>
where
Sender<T>: Freeze,
impl<T> RefUnwindSafe for SyncSender<T>
where
Sender<T>: RefUnwindSafe,
impl<T> Sync for SyncSender<T>
where
Sender<T>: Sync,
impl<T> Unpin for SyncSender<T>
where
Sender<T>: Unpin,
impl<T> UnsafeUnpin for SyncSender<T>
where
Sender<T>: UnsafeUnpin,
impl<T> UnwindSafe for SyncSender<T>
where
Sender<T>: UnwindSafe,
Blanket Implementations
impl<T> Any for SyncSender<T>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for SyncSender<T>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for SyncSender<T>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for SyncSender<T>
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for SyncSender<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> SizeHint for SyncSender<T>
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for SyncSender<T>
impl<T> ToOwned for SyncSender<T>
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for SyncSender<T>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for SyncSender<T>
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for SyncSender<T>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>