pub struct Receiver<T> { /* private fields */ }Implementations§
Source§impl<T> Receiver<T>
impl<T> Receiver<T>
Sourcepub fn try_recv(&self) -> Result<T, TryRecvError>
pub fn try_recv(&self) -> Result<T, TryRecvError>
Non-blocking receive, returns Err(TryRecvError::Empty) if buffer was empty; will
continue to receive pending messages from a disconnected channel until it is
empty, at which point further calls to this function will return
Err(TryRecvError::Disconnected).
Examples found in repository?
examples/sequential-try_recv.rs (line 34)
31fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
32 let start_time = std::time::SystemTime::now();
33 loop {
34 match receiver.try_recv() {
35 Ok (_m) => (),
36 Err (unbounded_spsc::TryRecvError::Empty) => (),
37 Err (unbounded_spsc::TryRecvError::Disconnected) => break
38 }
39 }
40 let duration = start_time.elapsed().unwrap();
41 let duration_ns
42 = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
43 println!("recvfun duration ns: {duration_ns}");
44 println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
45 println!("buffer ending capacity: {}", receiver.capacity());
46}More examples
examples/parallel-try_recv.rs (line 49)
41fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
42 RECEIVER_STARTED.store (true, std::sync::atomic::Ordering::SeqCst);
43 // spin until sender is started
44 while !SENDER_STARTED.load (std::sync::atomic::Ordering::SeqCst) {
45 std::hint::spin_loop()
46 }
47 let start_time = std::time::SystemTime::now();
48 loop {
49 match receiver.try_recv() {
50 Ok (_m) => (),
51 Err (unbounded_spsc::TryRecvError::Empty) => (),
52 Err (unbounded_spsc::TryRecvError::Disconnected) => break
53 }
54 }
55 let duration = start_time.elapsed().unwrap();
56 let duration_ns
57 = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
58 println!("recvfun duration ns: {duration_ns}");
59 println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
60 println!("buffer ending capacity: {}", receiver.capacity());
61}Sourcepub fn recv(&self) -> Result<T, RecvError>
pub fn recv(&self) -> Result<T, RecvError>
Block waiting if no messages are pending in the buffer.
Examples found in repository?
More examples
examples/parallel-recv.rs (line 48)
41fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
42 RECEIVER_STARTED.store (true, std::sync::atomic::Ordering::SeqCst);
43 // spin until sender is started
44 while !SENDER_STARTED.load (std::sync::atomic::Ordering::SeqCst) {
45 std::hint::spin_loop()
46 }
47 let start_time = std::time::SystemTime::now();
48 while let Ok (_m) = receiver.recv() { }
49 let duration = start_time.elapsed().unwrap();
50 let duration_ns = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos()
51 as u64;
52 println!("recvfun duration ns: {duration_ns}");
53 println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
54 println!("buffer ending capacity: {}", receiver.capacity());
55}pub fn recv_timeout(&self, timeout: Duration) -> Result<T, RecvTimeoutError>
pub const fn iter(&self) -> Iter<'_, T> ⓘ
pub const fn try_iter(&self) -> TryIter<'_, T> ⓘ
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Examples found in repository?
More examples
examples/sequential-try_recv.rs (line 45)
31fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
32 let start_time = std::time::SystemTime::now();
33 loop {
34 match receiver.try_recv() {
35 Ok (_m) => (),
36 Err (unbounded_spsc::TryRecvError::Empty) => (),
37 Err (unbounded_spsc::TryRecvError::Disconnected) => break
38 }
39 }
40 let duration = start_time.elapsed().unwrap();
41 let duration_ns
42 = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
43 println!("recvfun duration ns: {duration_ns}");
44 println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
45 println!("buffer ending capacity: {}", receiver.capacity());
46}examples/parallel-recv.rs (line 54)
41fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
42 RECEIVER_STARTED.store (true, std::sync::atomic::Ordering::SeqCst);
43 // spin until sender is started
44 while !SENDER_STARTED.load (std::sync::atomic::Ordering::SeqCst) {
45 std::hint::spin_loop()
46 }
47 let start_time = std::time::SystemTime::now();
48 while let Ok (_m) = receiver.recv() { }
49 let duration = start_time.elapsed().unwrap();
50 let duration_ns = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos()
51 as u64;
52 println!("recvfun duration ns: {duration_ns}");
53 println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
54 println!("buffer ending capacity: {}", receiver.capacity());
55}examples/parallel-try_recv.rs (line 60)
41fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
42 RECEIVER_STARTED.store (true, std::sync::atomic::Ordering::SeqCst);
43 // spin until sender is started
44 while !SENDER_STARTED.load (std::sync::atomic::Ordering::SeqCst) {
45 std::hint::spin_loop()
46 }
47 let start_time = std::time::SystemTime::now();
48 loop {
49 match receiver.try_recv() {
50 Ok (_m) => (),
51 Err (unbounded_spsc::TryRecvError::Empty) => (),
52 Err (unbounded_spsc::TryRecvError::Disconnected) => break
53 }
54 }
55 let duration = start_time.elapsed().unwrap();
56 let duration_ns
57 = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
58 println!("recvfun duration ns: {duration_ns}");
59 println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
60 println!("buffer ending capacity: {}", receiver.capacity());
61}Trait Implementations§
Source§impl<'a, T> IntoIterator for &'a Receiver<T>
impl<'a, T> IntoIterator for &'a Receiver<T>
Auto Trait Implementations§
impl<T> !Freeze for Receiver<T>
impl<T> !RefUnwindSafe for Receiver<T>
impl<T> Send for Receiver<T>where
T: Send,
impl<T> !Sync for Receiver<T>
impl<T> Unpin for Receiver<T>
impl<T> UnsafeUnpin for Receiver<T>
impl<T> !UnwindSafe for Receiver<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