pub struct Sender<T> { /* private fields */ }Implementations§
Source§impl<T> Sender<T>
impl<T> Sender<T>
Sourcepub fn send(&self, t: T) -> Result<(), SendError<T>>
pub fn send(&self, t: T) -> Result<(), SendError<T>>
Non-blocking send.
§Delivery guarantee
Returning Ok(()) indicates that the message was successfully enqueued, but it
does not guarantee that the receiver will observe it: if the Receiver is
dropped concurrently with this call, the message may be silently discarded. The
orphaned value is destructed properly when the underlying queue is dropped; it is
not leaked.
Examples found in repository?
examples/sequential-recv.rs (line 21)
17fn sendfun (sender : unbounded_spsc::Sender <Mystruct>) {
18 let mut counter = 0;
19 let start_time = std::time::SystemTime::now();
20 while counter < MESSAGE_COUNT {
21 sender.send (Mystruct { x: counter as f64, y: 1.5, z: 2.0 }).unwrap();
22 counter += 1;
23 }
24 let duration = start_time.elapsed().unwrap();
25 let duration_ns
26 = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
27 println!("sendfun duration ns: {duration_ns}");
28 println!("sendfun ns per message: {}", duration_ns / MESSAGE_COUNT);
29}More examples
examples/sequential-try_recv.rs (line 21)
17fn sendfun (sender : unbounded_spsc::Sender <Mystruct>) {
18 let mut counter = 0;
19 let start_time = std::time::SystemTime::now();
20 while counter < MESSAGE_COUNT {
21 sender.send (Mystruct { x: counter as f64, y: 1.5, z: 2.0 }).unwrap();
22 counter += 1;
23 }
24 let duration = start_time.elapsed().unwrap();
25 let duration_ns
26 = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
27 println!("sendfun duration ns: {duration_ns}");
28 println!("sendfun ns per message: {}", duration_ns / MESSAGE_COUNT);
29}examples/parallel-recv.rs (line 31)
22fn sendfun (sender : unbounded_spsc::Sender <Mystruct>) {
23 let mut counter = 0;
24 SENDER_STARTED.store (true, std::sync::atomic::Ordering::SeqCst);
25 // spin until receiver is started
26 while !RECEIVER_STARTED.load (std::sync::atomic::Ordering::SeqCst) {
27 std::hint::spin_loop()
28 }
29 let start_time = std::time::SystemTime::now();
30 while counter < MESSAGE_COUNT {
31 sender.send (Mystruct { x: counter as f64, y: 1.5, z: 2.0 }).unwrap();
32 counter += 1;
33 }
34 let duration = start_time.elapsed().unwrap();
35 let duration_ns
36 = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
37 println!("sendfun duration ns: {duration_ns}");
38 println!("sendfun ns per message: {}", duration_ns / MESSAGE_COUNT);
39}examples/parallel-try_recv.rs (line 31)
22fn sendfun (sender : unbounded_spsc::Sender <Mystruct>) {
23 let mut counter = 0;
24 SENDER_STARTED.store (true, std::sync::atomic::Ordering::SeqCst);
25 // spin until receiver is started
26 while !RECEIVER_STARTED.load (std::sync::atomic::Ordering::SeqCst) {
27 std::hint::spin_loop()
28 }
29 let start_time = std::time::SystemTime::now();
30 while counter < MESSAGE_COUNT {
31 sender.send (Mystruct { x: counter as f64, y: 1.5, z: 2.0 }).unwrap();
32 counter += 1;
33 }
34 let duration = start_time.elapsed().unwrap();
35 let duration_ns
36 = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
37 println!("sendfun duration ns: {duration_ns}");
38 println!("sendfun ns per message: {}", duration_ns / MESSAGE_COUNT);
39}Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for Sender<T>
impl<T> !RefUnwindSafe for Sender<T>
impl<T> Send for Sender<T>where
T: Send,
impl<T> !Sync for Sender<T>
impl<T> Unpin for Sender<T>
impl<T> UnsafeUnpin for Sender<T>
impl<T> !UnwindSafe for Sender<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more