Struct abi_stable::external_types::crossbeam_channel::RReceiver [−][src]
#[repr(C)]pub struct RReceiver<T> { /* fields omitted */ }
channels
only.Expand description
The receiver end of a channel, which can be either bounded or unbounded.
Examples
use abi_stable::external_types::crossbeam_channel as mpmc;
let (tx, rx) = mpmc::unbounded::<&'static str>();
let join_guard = std::thread::spawn(move || {
assert_eq!(rx.recv().unwrap(), "PING");
assert_eq!(rx.recv().unwrap(), "PING");
assert_eq!(rx.recv().unwrap(), "PING");
assert_eq!(rx.recv().unwrap(), "PING");
assert!(rx.try_recv().unwrap_err().is_empty());
});
for _ in 0..4 {
tx.send("PING").unwrap();
}
join_guard.join().unwrap();
assert!(tx.send("").is_err());
Implementations
Blocks until a value is either received,or the the other end is disconnected.
If the channel queue is empty,this will block to receive a value.
This will return an error if the channel is disconnected.
Example
use abi_stable::external_types::crossbeam_channel as mpmc;
let (tx, rx) = mpmc::bounded::<&'static str>(3);
tx.send("J__e H____y").unwrap();
assert_eq!(rx.recv().unwrap(), "J__e H____y");
drop(tx);
assert!(rx.recv().is_err());
Immediately receives a value,or returns with an error.
An error will be returned in these 2 conditions:
-
the channel is empty.
-
the channel has been disconnected.
If the channel has a capacity of 0,it will only receive a value if
the other end is calling send
.
Example
use abi_stable::external_types::crossbeam_channel as mpmc;
let (tx, rx) = mpmc::bounded::<&'static str>(3);
assert!(rx.try_recv().is_err());
tx.send("D__e S_____r").unwrap();
assert_eq!(rx.try_recv().unwrap(), "D__e S_____r");
drop(tx);
assert!(rx.try_recv().is_err());
Blocks until a timeout to receive a value.
An error will be returned in these 2 conditions:
-
A value could not be received before the timeout.
-
the channel has been disconnected.
If the channel has a capacity of 0,it will only receive a value if
the other end calls send
before the timeout.
Example
use abi_stable::external_types::crossbeam_channel as mpmc;
use std::time::Duration;
let (tx, rx) = mpmc::bounded::<&'static str>(3);
let timeout = Duration::from_millis(1);
assert!(rx.recv_timeout(timeout).unwrap_err().is_timeout());
tx.send("D__e S_____r").unwrap();
assert_eq!(rx.recv_timeout(timeout).unwrap(), "D__e S_____r");
drop(tx);
assert!(rx.recv_timeout(timeout).unwrap_err().is_disconnected());
Returns true if there are no values in the channel queue.
Example
use abi_stable::external_types::crossbeam_channel as mpmc;
let (tx, rx) = mpmc::bounded::<()>(1);
assert!(rx.is_empty());
tx.send(()).unwrap();
assert!(!rx.is_empty());
rx.recv().unwrap();
assert!(rx.is_empty());
Returns true if the channel queue is full.
This always returns true for channels constructed with bounded(0)
.
Example
use abi_stable::external_types::crossbeam_channel as mpmc;
let (tx, rx) = mpmc::bounded::<()>(2);
assert!(!rx.is_full());
tx.send(()).unwrap();
assert!(!rx.is_full());
tx.send(()).unwrap();
assert!(rx.is_full());
rx.recv().unwrap();
assert!(!rx.is_full());
Returns the amount of values in the channel queue.
Example
use abi_stable::external_types::crossbeam_channel as mpmc;
let (tx, rx) = mpmc::bounded::<()>(2);
assert_eq!(rx.len(), 0);
tx.send(()).unwrap();
assert_eq!(rx.len(), 1);
tx.send(()).unwrap();
assert_eq!(rx.len(), 2);
rx.recv().unwrap();
assert_eq!(rx.len(), 1);
Returns the amount of values the channel queue can hold.
This returns None if the channel is unbounded.
Example
use abi_stable::external_types::crossbeam_channel as mpmc;
{
let (tx, rx) = mpmc::bounded::<()>(2);
assert_eq!(rx.capacity(), Some(2));
}
{
let (tx, rx) = mpmc::unbounded::<()>();
assert_eq!(rx.capacity(), None);
}
Creates an Iterator that receives values from the channel.
Example
use abi_stable::external_types::crossbeam_channel as mpmc;
use std::thread;
let (tx, rx) = mpmc::bounded::<usize>(1);
thread::spawn(move || {
for i in 0..1000 {
tx.send(i).unwrap();
}
});
for (i, n) in rx.iter().enumerate() {
assert_eq!(i, n);
}
Trait Implementations
type StaticEquivalent = _static_RReceiver<__GetStaticEquivalent<T>>
Creates an Iterator that receives values from the channel.
type Item = T
type Item = T
The type of the elements being iterated over.
Creates an Iterator that receives values from the channel.
type Item = T
type Item = T
The type of the elements being iterated over.
type IsNonZeroType = False
type IsNonZeroType = False
Whether this type has a single invalid bit-pattern. Read more
The layout of the type provided by implementors.
const
-equivalents of the associated types.
Auto Trait Implementations
impl<T> RefUnwindSafe for RReceiver<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for RReceiver<T> where
T: UnwindSafe + RefUnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
type ROwned = T
type ROwned = T
The owned type, stored in RCow::Owned
type ForSelf = WithMetadata_<T, T>
type ForSelf = WithMetadata_<T, T>
This is always WithMetadata_<Self, Self>
Compares the address of self
with the address of other
. Read more
Emulates the pipeline operator, allowing method syntax in more places. Read more
The same as piped
except that the function takes &Self
Useful for functions that take &Self
instead of Self
. Read more
The same as piped
, except that the function takes &mut Self
.
Useful for functions that take &mut Self
instead of Self
. Read more
Mutates self using a closure taking self by mutable reference, passing it along the method chain. Read more
Observes the value of self, passing it along unmodified. Useful in long method chains. Read more
Performs a conversion with Into
.
using the turbofish .into_::<_>()
syntax. Read more
Performs a reference to reference conversion with AsRef
,
using the turbofish .as_ref_::<_>()
syntax. Read more
Performs a mutable reference to mutable reference conversion with AsMut
,
using the turbofish .as_mut_::<_>()
syntax. Read more
unsafe fn transmute_element<T>(
self
) -> <Self as CanTransmuteElement<T>>::TransmutedPtr where
Self: CanTransmuteElement<T>,
unsafe fn transmute_element<T>(
self
) -> <Self as CanTransmuteElement<T>>::TransmutedPtr where
Self: CanTransmuteElement<T>,
Transmutes the element type of this pointer.. Read more
type Type = T
type Type = T
This is always Self
.
Converts a value back to the original type.
Converts a mutable reference back to the original type.
alloc
only.Converts a box back to the original type.
Converts a value back to the original type.
Converts a reference back to the original type.
Converts a mutable reference back to the original type.
alloc
only.Converts a box back to the original type.
alloc
only.Converts an Arc back to the original type.
alloc
only.Converts an Rc back to the original type.