Struct abi_stable::external_types::crossbeam_channel::RReceiver[][src]

#[repr(C)]
pub struct RReceiver<T> { /* fields omitted */ }
This is supported on crate feature 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

Clones this channel end,getting another handle into the channel.

Note that this allocates an RBox<_>.

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Creates an Iterator that receives values from the channel.

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an Iterator that receives values from the channel.

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

The owned type, stored in RCow::Owned

The borrowed type, stored in RCow::Borrowed

Performs the conversion.

This is always WithMetadata_<Self, Self>

Performs the conversion.

Gets a reference to a field, determined by offset. Read more

Gets a muatble reference to a field, determined by offset. Read more

Gets a const pointer to a field, the field is determined by offset. Read more

Gets a mutable pointer to a field, determined by offset. Read more

Replaces a field (determined by offset) with value, returning the previous value of the field. Read more

Swaps a field (determined by offset) with the same field in right. Read more

Gets a copy of a field (determined by offset). The field is determined by offset. Read more

Replaces a field (determined by offset) with value, returning the previous value of the field. Read more

Swaps a field (determined by offset) with the same field in right. Read more

Gets a copy of a field (determined by offset). The field is determined by offset. Read more

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

Drops self using method notation. Alternative to std::mem::drop. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Transmutes the element type of this pointer.. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

This is always Self.

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.

This is supported on crate feature alloc only.

Converts a box back to the original type.

This is supported on crate feature alloc only.

Converts an Arc back to the original type. Read more

This is supported on crate feature alloc only.

Converts an Rc back to the original type. Read more

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.

This is supported on crate feature alloc only.

Converts a box back to the original type.

This is supported on crate feature alloc only.

Converts an Arc back to the original type.

This is supported on crate feature alloc only.

Converts an Rc back to the original type.