pub struct Receiver<T> { /* private fields */ }
Expand description
The receiving half of a channel.
Implementations§
Source§impl<T> Receiver<T>
impl<T> Receiver<T>
Sourcepub fn recv(&mut self) -> Result<T, RecvError>
pub fn recv(&mut self) -> Result<T, RecvError>
Receive data sent by the corresponding Sender
.
This will block until a value is actually sent, if none is already.
§Errors
If the corresponding Sender
is already dropped (or gets dropped during the wait),
this method will return Err(RecvError)
.
§Examples
Success:
use std::thread;
use pipe_channel::*;
let (mut tx, mut rx) = channel();
let handle = thread::spawn(move || {
tx.send(35).unwrap();
tx.send(42).unwrap();
});
assert_eq!(rx.recv().unwrap(), 35);
assert_eq!(rx.recv().unwrap(), 42);
handle.join().unwrap();
Failure:
use pipe_channel::*;
use std::sync::mpsc::RecvError;
use std::mem::drop;
let (tx, mut rx) = channel::<i32>();
drop(tx);
assert_eq!(rx.recv(), Err(RecvError));
Sourcepub fn iter(&mut self) -> Iter<'_, T> ⓘ
pub fn iter(&mut self) -> Iter<'_, T> ⓘ
Get an iterator over data sent through the channel.
§Examples
use pipe_channel::*;
use std::mem::drop;
let (mut tx, mut rx) = channel();
for i in 0..1024 {
tx.send(i).unwrap();
}
drop(tx);
for (i, j) in rx.iter().take(10).zip(0..10) {
assert_eq!(i, j);
}
let v1: Vec<_> = rx.into_iter().collect();
let v2: Vec<_> = (10..1024).collect();
assert_eq!(v1, v2);
Trait Implementations§
Source§impl<T> FromRawFd for Receiver<T>
impl<T> FromRawFd for Receiver<T>
Source§unsafe fn from_raw_fd(fd: RawFd) -> Self
unsafe fn from_raw_fd(fd: RawFd) -> Self
Constructs a new instance of
Self
from the given raw file
descriptor. Read moreSource§impl<'a, T: 'a> IntoIterator for &'a mut Receiver<T>
impl<'a, T: 'a> IntoIterator for &'a mut Receiver<T>
Source§impl<T> IntoIterator for Receiver<T>
impl<T> IntoIterator for Receiver<T>
Source§impl<T> IntoRawFd for Receiver<T>
impl<T> IntoRawFd for Receiver<T>
Source§fn into_raw_fd(self) -> RawFd
fn into_raw_fd(self) -> RawFd
Consumes this object, returning the raw underlying file descriptor. Read more
impl<T: Send> Send for Receiver<T>
Auto Trait Implementations§
impl<T> Freeze for Receiver<T>
impl<T> RefUnwindSafe for Receiver<T>
impl<T> !Sync for Receiver<T>
impl<T> Unpin 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