[][src]Struct multiqueue2::MPMCUniReceiver

pub struct MPMCUniReceiver<T> { /* fields omitted */ }

This is the receiving end of a standard mpmc view of the queue for when it's statically know that there is only one receiver. It functions similarly to the BroadcastUniReceiver execpt there is only ever one stream. As a result, the type doesn't need to be clone or sync

Implementations

impl<T> MPMCUniReceiver<T>[src]

pub fn try_recv(&self) -> Result<T, TryRecvError>[src]

Identical to MPMCReceiver::try_recv

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

Identical to MPMCReceiver::recv

pub fn try_recv_view<R, F: FnOnce(&T) -> R>(
    &self,
    op: F
) -> Result<R, (F, TryRecvError)>
[src]

Applies the passed function to the value in the queue without copying it out If there is no data in the queue or the writers have disconnected, returns an Err((F, TryRecvError))

Example

use multiqueue2::mpmc_queue;

let (w, r) = mpmc_queue(10);
let single_r = r.into_single().unwrap();
for i in 0..5 {
    w.try_send(i).unwrap();
}

for i in 0..5 {
    let val = match single_r.try_recv_view(|x| 1 + *x) {
        Ok(val) => val,
        Err(_) => panic!("Queue shouldn't be disconncted or empty"),
    };
    assert_eq!(i + 1, val);
}
assert!(single_r.try_recv_view(|x| *x).is_err());
drop(w);
assert!(single_r.try_recv_view(|x| *x).is_err());

pub fn recv_view<R, F: FnOnce(&T) -> R>(
    &self,
    op: F
) -> Result<R, (F, RecvError)>
[src]

Applies the passed function to the value in the queue without copying it out If there is no data in the queue, blocks until an item is pushed into the queue or all writers disconnect

Example

use multiqueue2::mpmc_queue;

let (w, r) = mpmc_queue(10);
let single_r = r.into_single().unwrap();
for i in 0..5 {
    w.try_send(i).unwrap();
}

for i in 0..5 {
    let val = match single_r.recv_view(|x| 1 + *x) {
        Ok(val) => val,
        Err(_) => panic!("Queue shouldn't be disconncted or empty"),
    };
    assert_eq!(i + 1, val);
}
drop(w);
assert!(single_r.recv_view(|x| *x).is_err());

pub fn unsubscribe(self) -> bool[src]

Removes the given reader from the queue subscription lib Returns true if this is the last reader in a given broadcast unit

Examples

use multiqueue2::mpmc_queue;
let (writer, reader) = mpmc_queue(2);
writer.try_send(1).expect("This will succeed since queue is empty");
reader.try_recv().expect("This reader can read");
reader.unsubscribe();
// Fails since there's no readers left
assert!(writer.try_send(1).is_err());

pub fn into_multi(self) -> MPMCReceiver<T>[src]

Transforms the MPMCUniReceiver into a MPMCReceiver

Example

use multiqueue2::mpmc_queue;

let (w, r) = mpmc_queue(10);
w.try_send(1).unwrap();
let single_r = r.into_single().unwrap();
let normal_r = single_r.into_multi();
normal_r.clone();

pub fn iter_with<R, F: FnMut(&T) -> R>(self, op: F) -> MPMCUniIter<R, F, T>[src]

Returns a non-owning iterator that iterates over the queue until it fails to receive an item, either through being empty or begin disconnected. This iterator will never block.

Examples:

use multiqueue2::mpmc_queue;
let (w, r) = mpmc_queue(2);
let sr = r.into_single().unwrap();
w.try_send(1).unwrap();
w.try_send(2).unwrap();
w.unsubscribe();
for val in sr.iter_with(|x| 2 * *x).zip(1..2) {
    assert_eq!(val.0, val.1 * 2);
}

pub fn try_iter_with<R, F: FnMut(&T) -> R>(
    &self,
    op: F
) -> MPMCUniRefIter<'_, R, F, T>
[src]

Returns a non-owning iterator that iterates over the queue until it fails to receive an item, either through being empty or begin disconnected. This iterator will never block.

Examples:

use multiqueue2::mpmc_queue;
let (w, r) = mpmc_queue(2);
let sr = r.into_single().unwrap();
for _ in 0 .. 3 {
    w.try_send(1).unwrap();
    w.try_send(2).unwrap();
    for val in sr.try_iter_with(|x| 2 * *x).zip(1..2) {
        assert_eq!(val.0, val.1*2);
    }
}

Trait Implementations

impl<T> IntoIterator for MPMCUniReceiver<T>[src]

type Item = T

The type of the elements being iterated over.

type IntoIter = MPSCIter<T>

Which kind of iterator are we turning this into?

impl<'a, T: 'a> IntoIterator for &'a MPMCUniReceiver<T>[src]

type Item = T

The type of the elements being iterated over.

type IntoIter = MPSCRefIter<'a, T>

Which kind of iterator are we turning this into?

impl<T: Send> Send for MPMCUniReceiver<T>[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.