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"));
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();
}
Implementations§
Source§impl Multipart
impl Multipart
pub fn new() -> Self
pub fn into_inner(self) -> VecDeque<Message>
pub fn get(&self, index: usize) -> Option<&Message>
pub fn pop_front(&mut self) -> Option<Message>
pub fn pop_back(&mut self) -> Option<Message>
pub fn push_front(&mut self, msg: Message)
pub fn push_back(&mut self, msg: Message)
pub fn is_empty(&self) -> bool
pub fn iter(&self) -> Iter<'_, Message>
pub fn len(&self) -> usize
pub fn iter_mut(&mut self) -> IterMut<'_, Message>
pub fn drain<R>(&mut self, range: R) -> Drain<'_, Message>where
R: RangeBounds<usize>,
Trait Implementations§
Source§impl<'a> IntoIterator for &'a Multipart
impl<'a> IntoIterator for &'a Multipart
Source§impl<'a> IntoIterator for &'a mut Multipart
impl<'a> IntoIterator for &'a mut Multipart
Auto Trait Implementations§
impl Freeze for Multipart
impl RefUnwindSafe for Multipart
impl Send for Multipart
impl Sync for Multipart
impl Unpin for Multipart
impl UnwindSafe for Multipart
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more