[][src]Struct async_zmq_types::Multipart

pub struct Multipart { /* fields omitted */ }

This type is used for receiving and sending messages in Multipart groups. An application could make using this easier by implementing traits as follows:

extern crate zmq;
extern crate tokio_zmq;

use tokio_zmq::Multipart;

#[derive(Debug)]
enum Error {
    NotEnoughMessages,
    TooManyMessages,
}

struct Envelope {
    filter: zmq::Message,
    address: zmq::Message,
    body: zmq::Message,
}

impl Envelope {
    fn from_multipart(mut multipart: Multipart) -> Result<Self, Error> {
        let filter = multipart.pop_front().ok_or(Error::NotEnoughMessages)?;
        let address = multipart.pop_front().ok_or(Error::NotEnoughMessages)?;
        let body = multipart.pop_front().ok_or(Error::NotEnoughMessages)?;

        if !multipart.is_empty() {
            return Err(Error::TooManyMessages);
        }

        Ok(Envelope {
            filter,
            address,
            body,
        })
    }
}

impl From<Envelope> for Multipart {
    fn from(envelope: Envelope) -> Self {
        let mut multipart = Multipart::new();

        multipart.push_back(envelope.filter);
        multipart.push_back(envelope.address);
        multipart.push_back(envelope.body);

        multipart
    }
}

fn main() {
    let mut multipart: Multipart = Multipart::new();
    multipart.push_back(zmq::Message::from_slice(b"FILTER: asdf"));
    multipart.push_back(zmq::Message::from_slice(b"some.address"));
    multipart.push_back(zmq::Message::from_slice(b"Some content"));
    let envelope = Envelope::from_multipart(multipart).unwrap();

    let multipart2: Multipart = envelope.into();
}

Methods

impl Multipart
[src]

pub fn new() -> Self
[src]

pub fn into_inner(self) -> VecDeque<Message>
[src]

pub fn get(&self, index: usize) -> Option<&Message>
[src]

pub fn pop_front(&mut self) -> Option<Message>
[src]

pub fn pop_back(&mut self) -> Option<Message>
[src]

pub fn push_front(&mut self, msg: Message)
[src]

pub fn push_back(&mut self, msg: Message)
[src]

pub fn is_empty(&self) -> bool
[src]

pub fn iter(&self) -> Iter<Message>
[src]

pub fn len(&self) -> usize
[src]

pub fn iter_mut(&mut self) -> IterMut<Message>
[src]

pub fn drain<R>(&mut self, range: R) -> Drain<Message> where
    R: RangeBounds<usize>, 
[src]

Trait Implementations

impl From<Message> for Multipart
[src]

impl From<Vec<Message>> for Multipart
[src]

impl<'a> IntoIterator for &'a Multipart
[src]

type Item = &'a Message

The type of the elements being iterated over.

type IntoIter = Iter<'a, Message>

Which kind of iterator are we turning this into?

impl IntoIterator for Multipart
[src]

type Item = Message

The type of the elements being iterated over.

type IntoIter = IntoIter<Message>

Which kind of iterator are we turning this into?

impl<'a> IntoIterator for &'a mut Multipart
[src]

type Item = &'a mut Message

The type of the elements being iterated over.

type IntoIter = IterMut<'a, Message>

Which kind of iterator are we turning this into?

impl Default for Multipart
[src]

impl Debug for Multipart
[src]

Auto Trait Implementations

impl Send for Multipart

impl Sync for Multipart

Blanket Implementations

impl<T> From for T
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

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

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

type Error = !

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

The type returned in the event of a conversion error.

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

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

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

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

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

The type returned in the event of a conversion error.

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