Struct rumqttlog::Receiver[][src]

pub struct Receiver<T> { /* fields omitted */ }
Expand description

The receiving side of a channel.

Receivers can be cloned and shared among threads. When all receivers associated with a channel are dropped, the channel becomes closed.

The channel can also be closed manually by calling Receiver::close().

Receivers implement the [Stream] trait.

Implementations

Attempts to receive a message from the channel.

If the channel is empty or closed, this method returns an error.

Examples
use jackiechan::{bounded, TryRecvError};

let (s, r) = bounded(10);
assert_eq!(s.send(1), Ok(()));

assert_eq!(r.try_recv(), Ok(1));
assert_eq!(r.try_recv(), Err(TryRecvError::Empty));

drop(s);
assert_eq!(r.try_recv(), Err(TryRecvError::Closed));

Receives a message from the channel.

If the channel is empty, this method waits until there is a message.

If the channel is closed, this method receives a message or returns an error if there are no more messages.

Examples
use jackiechan::{bounded, RecvError};

let (s, r) = bounded(10);

assert_eq!(s.send(1), Ok(()));
drop(s);

assert_eq!(r.recv(), Ok(1));
assert_eq!(r.recv(), Err(RecvError));

Receives a message from the channel.

If the channel is empty, this method waits until there is a message.

If the channel is closed, this method receives a message or returns an error if there are no more messages.

Examples
use jackiechan::{bounded, RecvTimeoutError};
use std::time::Duration;

let (s, r) = bounded(10);

assert_eq!(s.send(1), Ok(()));
assert_eq!(r.recv_timeout(Duration::from_secs(1)), Ok(1));
assert_eq!(r.recv_timeout(Duration::from_secs(1)), Err(RecvTimeoutError::Timeout));

Receives a message from the channel.

If the channel is empty, this method waits until there is a message.

If the channel is closed, this method receives a message or returns an error if there are no more messages.

Examples
use jackiechan::{bounded, RecvTimeoutError};
use std::time::{Instant, Duration};

let (s, r) = bounded(10);

assert_eq!(s.send(1), Ok(()));

assert_eq!(r.recv_deadline(Instant::now() + Duration::from_secs(1)), Ok(1));
assert_eq!(r.recv_deadline(Instant::now() + Duration::from_secs(1)), Err(RecvTimeoutError::Timeout));

Receives a message from the channel. If the channel is empty, this method waits until there is a message.

If the channel is closed, this method receives a message or returns an error if there are no more messages.

Closes the channel.

Returns true if this call has closed the channel and it was not closed already.

The remaining messages can still be received.

Examples
use jackiechan::{bounded, RecvError};

let (s, r) = bounded(10);
assert_eq!(s.send(1), Ok(()));

assert!(r.close());
assert_eq!(r.recv(), Ok(1));
assert_eq!(r.recv(), Err(RecvError));

Returns true if the channel is closed.

Examples
use jackiechan::{bounded, RecvError};

let (s, r) = bounded::<()>(10);
assert!(!r.is_closed());

drop(s);
assert!(r.is_closed());

Returns true if the channel is empty.

Examples
use jackiechan::bounded;

let (s, r) = bounded(10);

assert!(s.is_empty());
s.send(1);
assert!(!s.is_empty());

Returns true if the channel is full.

Examples
use jackiechan::bounded;

let (s, r) = bounded(1);

assert!(!r.is_full());
s.send(1);
assert!(r.is_full());

Returns the number of messages in the channel.

Examples
use jackiechan::bounded;

let (s, r) = bounded(10);
assert_eq!(r.len(), 0);

s.send(1);
s.send(2);
assert_eq!(r.len(), 2);

Returns the channel capacity if it’s bounded.

Examples
use jackiechan::{bounded};

let (s, r) = bounded::<i32>(5);
assert_eq!(r.capacity(), Some(5));

Returns the number of receivers for the channel.

Examples
use jackiechan::bounded;

let (s, r) = bounded::<()>(10);
assert_eq!(r.receiver_count(), 1);

let r2 = r.clone();
assert_eq!(r.receiver_count(), 2);

Returns the number of senders for the channel.

Examples
use jackiechan::bounded;

let (s, r) = bounded::<()>(10);
assert_eq!(r.sender_count(), 1);

let s2 = s.clone();
assert_eq!(r.sender_count(), 2);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

Values yielded by the stream.

Attempt to pull out the next value of this stream, registering the current task for wakeup if the value is not yet available, and returning None if the stream is exhausted. Read more

Returns the bounds on the remaining length of the stream. Read more

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

Performs the conversion.

Performs the conversion.

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

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.

The type of successful values yielded by this future

The type of failures yielded by this future

Poll this TryStream as if it were a Stream. Read more