Struct tokio_zmq::Multipart
[−]
[src]
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:
#![feature(try_from)] extern crate zmq; extern crate tokio_zmq; use std::convert::{TryFrom, TryInto}; use tokio_zmq::Multipart; #[derive(Debug)] enum Error { NotEnoughMessages, TooManyMessages, } struct Envelope { filter: zmq::Message, address: zmq::Message, body: zmq::Message, } impl TryFrom<Multipart> for Envelope { type Error = Error; fn try_from(mut multipart: Multipart) -> Result<Self, 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 = multipart.try_into().unwrap(); let multipart2: Multipart = envelope.into(); }
Methods
impl Multipart
[src]
fn new() -> Self
[src]
fn into_inner(self) -> VecDeque<Message>
[src]
fn get(&self, index: usize) -> Option<&Message>
[src]
fn pop_front(&mut self) -> Option<Message>
[src]
fn pop_back(&mut self) -> Option<Message>
[src]
fn push_front(&mut self, msg: Message)
[src]
fn push_back(&mut self, msg: Message)
[src]
fn is_empty(&self) -> bool
[src]
fn iter(&self) -> Iter<Message>
[src]
fn iter_mut(&mut self) -> IterMut<Message>
[src]
Trait Implementations
impl Debug for Multipart
[src]
impl Default for Multipart
[src]
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?
fn into_iter(self) -> Iter<'a, Message>
[src]
Creates an iterator from a value. Read more
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?
fn into_iter(self) -> IntoIter<Message>
[src]
Creates an iterator from a value. Read more