Struct unbounded_spsc::Sender
source · 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.
Examples found in repository?
examples/sequential-recv.rs (line 20)
16 17 18 19 20 21 22 23 24 25 26 27 28
fn sendfun (sender : unbounded_spsc::Sender <Mystruct>) {
let mut counter = 0;
let start_time = std::time::SystemTime::now();
while counter < MESSAGE_COUNT {
sender.send (Mystruct { x: counter as f64, y: 1.5, z: 2.0 }).unwrap();
counter += 1;
}
let duration = start_time.elapsed().unwrap();
let duration_ns
= (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
println!("sendfun duration ns: {}", duration_ns);
println!("sendfun ns per message: {}", duration_ns / MESSAGE_COUNT);
}
More examples
examples/sequential-try_recv.rs (line 20)
16 17 18 19 20 21 22 23 24 25 26 27 28
fn sendfun (sender : unbounded_spsc::Sender <Mystruct>) {
let mut counter = 0;
let start_time = std::time::SystemTime::now();
while counter < MESSAGE_COUNT {
sender.send (Mystruct { x: counter as f64, y: 1.5, z: 2.0 }).unwrap();
counter += 1;
}
let duration = start_time.elapsed().unwrap();
let duration_ns
= (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
println!("sendfun duration ns: {}", duration_ns);
println!("sendfun ns per message: {}", duration_ns / MESSAGE_COUNT);
}
examples/parallel-recv.rs (line 28)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
fn sendfun (sender : unbounded_spsc::Sender <Mystruct>) {
let mut counter = 0;
SENDER_STARTED.store (true, std::sync::atomic::Ordering::SeqCst);
// spin until receiver is started
while !RECEIVER_STARTED.load (std::sync::atomic::Ordering::SeqCst) {}
let start_time = std::time::SystemTime::now();
while counter < MESSAGE_COUNT {
sender.send (Mystruct { x: counter as f64, y: 1.5, z: 2.0 }).unwrap();
counter += 1;
}
let duration = start_time.elapsed().unwrap();
let duration_ns
= (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
println!("sendfun duration ns: {}", duration_ns);
println!("sendfun ns per message: {}", duration_ns / MESSAGE_COUNT);
}
examples/parallel-try_recv.rs (line 28)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
fn sendfun (sender : unbounded_spsc::Sender <Mystruct>) {
let mut counter = 0;
SENDER_STARTED.store (true, std::sync::atomic::Ordering::SeqCst);
// spin until receiver is started
while !RECEIVER_STARTED.load (std::sync::atomic::Ordering::SeqCst) {}
let start_time = std::time::SystemTime::now();
while counter < MESSAGE_COUNT {
sender.send (Mystruct { x: counter as f64, y: 1.5, z: 2.0 }).unwrap();
counter += 1;
}
let duration = start_time.elapsed().unwrap();
let duration_ns
= (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
println!("sendfun duration ns: {}", duration_ns);
println!("sendfun ns per message: {}", duration_ns / MESSAGE_COUNT);
}
Trait Implementations§
Auto Trait Implementations§
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> !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