pub struct Receiver<T> { /* private fields */ }

Implementations§

source§

impl<T> Receiver<T>

source

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 33)
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
  let start_time = std::time::SystemTime::now();
  loop {
    match receiver.try_recv() {
      Ok  (_m) => (),
      Err (unbounded_spsc::TryRecvError::Empty) => (),
      Err (unbounded_spsc::TryRecvError::Disconnected) => break
    }
  }
  let duration = start_time.elapsed().unwrap();
  let duration_ns
    = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
  println!("recvfun duration ns: {}", duration_ns);
  println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
  println!("buffer ending capacity: {}", receiver.capacity());
}
More examples
Hide additional examples
examples/parallel-try_recv.rs (line 44)
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
  RECEIVER_STARTED.store (true, std::sync::atomic::Ordering::SeqCst);
  // spin until sender is started
  while !SENDER_STARTED.load (std::sync::atomic::Ordering::SeqCst) {}
  let start_time = std::time::SystemTime::now();
  loop {
    match receiver.try_recv() {
      Ok  (_m) => (),
      Err (unbounded_spsc::TryRecvError::Empty) => (),
      Err (unbounded_spsc::TryRecvError::Disconnected) => break
    }
  }
  let duration = start_time.elapsed().unwrap();
  let duration_ns
    = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
  println!("recvfun duration ns: {}", duration_ns);
  println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
  println!("buffer ending capacity: {}", receiver.capacity());
}
source

pub fn recv(&self) -> Result<T, RecvError>

Block waiting if no messages are pending in the buffer.

Examples found in repository?
examples/sequential-recv.rs (line 33)
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
  let start_time = std::time::SystemTime::now();
  loop {
    match receiver.recv() {
      Ok  (_m) => (),
      Err (_e) => break
    }
  }
  let duration = start_time.elapsed().unwrap();
  let duration_ns
    = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
  println!("recvfun duration ns: {}", duration_ns);
  println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
  println!("buffer ending capacity: {}", receiver.capacity());
}
More examples
Hide additional examples
examples/parallel-recv.rs (line 44)
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
  RECEIVER_STARTED.store (true, std::sync::atomic::Ordering::SeqCst);
  // spin until sender is started
  while !SENDER_STARTED.load (std::sync::atomic::Ordering::SeqCst) {}
  let start_time = std::time::SystemTime::now();
  loop {
    match receiver.recv() {
      Ok  (_m) => (),
      Err (_e) => break
    }
  }
  let duration = start_time.elapsed().unwrap();
  let duration_ns
    = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
  println!("recvfun duration ns: {}", duration_ns);
  println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
  println!("buffer ending capacity: {}", receiver.capacity());
}
source

pub fn recv_timeout(&self, timeout: Duration) -> Result<T, RecvTimeoutError>

source

pub fn iter(&self) -> Iter<'_, T>

source

pub fn try_iter(&self) -> TryIter<'_, T>

source

pub fn capacity(&self) -> usize

Examples found in repository?
examples/sequential-recv.rs (line 43)
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
  let start_time = std::time::SystemTime::now();
  loop {
    match receiver.recv() {
      Ok  (_m) => (),
      Err (_e) => break
    }
  }
  let duration = start_time.elapsed().unwrap();
  let duration_ns
    = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
  println!("recvfun duration ns: {}", duration_ns);
  println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
  println!("buffer ending capacity: {}", receiver.capacity());
}
More examples
Hide additional examples
examples/sequential-try_recv.rs (line 44)
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
  let start_time = std::time::SystemTime::now();
  loop {
    match receiver.try_recv() {
      Ok  (_m) => (),
      Err (unbounded_spsc::TryRecvError::Empty) => (),
      Err (unbounded_spsc::TryRecvError::Disconnected) => break
    }
  }
  let duration = start_time.elapsed().unwrap();
  let duration_ns
    = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
  println!("recvfun duration ns: {}", duration_ns);
  println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
  println!("buffer ending capacity: {}", receiver.capacity());
}
examples/parallel-recv.rs (line 54)
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
  RECEIVER_STARTED.store (true, std::sync::atomic::Ordering::SeqCst);
  // spin until sender is started
  while !SENDER_STARTED.load (std::sync::atomic::Ordering::SeqCst) {}
  let start_time = std::time::SystemTime::now();
  loop {
    match receiver.recv() {
      Ok  (_m) => (),
      Err (_e) => break
    }
  }
  let duration = start_time.elapsed().unwrap();
  let duration_ns
    = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
  println!("recvfun duration ns: {}", duration_ns);
  println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
  println!("buffer ending capacity: {}", receiver.capacity());
}
examples/parallel-try_recv.rs (line 55)
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
  RECEIVER_STARTED.store (true, std::sync::atomic::Ordering::SeqCst);
  // spin until sender is started
  while !SENDER_STARTED.load (std::sync::atomic::Ordering::SeqCst) {}
  let start_time = std::time::SystemTime::now();
  loop {
    match receiver.try_recv() {
      Ok  (_m) => (),
      Err (unbounded_spsc::TryRecvError::Empty) => (),
      Err (unbounded_spsc::TryRecvError::Disconnected) => break
    }
  }
  let duration = start_time.elapsed().unwrap();
  let duration_ns
    = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
  println!("recvfun duration ns: {}", duration_ns);
  println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
  println!("buffer ending capacity: {}", receiver.capacity());
}
source

pub fn can_recv(&self) -> bool

source

pub fn start_selection(&self, token: SignalToken) -> SelectionResult

Trait Implementations§

source§

impl<T> Debug for Receiver<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Drop for Receiver<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'a, T> IntoIterator for &'a Receiver<T>

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Iter<'a, T>

Creates an iterator from a value. Read more
source§

impl<T> IntoIterator for Receiver<T>

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> IntoIter<T>

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

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> !UnwindSafe for Receiver<T>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.