pub struct Multipart { /* private fields */ }
Expand description

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").unwrap());
    multipart.push_back(zmq::Message::from_slice(b"some.address").unwrap());
    multipart.push_back(zmq::Message::from_slice(b"Some content").unwrap());
    let envelope = Envelope::from_multipart(multipart).unwrap();

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

Implementations

Trait Implementations

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Converts to this type from the input type.
Converts to this type from the input type.
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. 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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.