pub struct ZmqMessage { /* private fields */ }Expand description
A multi-frame ZMQ message.
Construct from a single frame via From<Bytes>, From<Vec<u8>>, From<String>, or
From<&str>. For multi-frame messages use push_back or
TryFrom<Vec<Bytes>>.
§Examples
use rustzmq2::ZmqMessage;
use bytes::Bytes;
// Single-frame from any byte-ish input.
let m1: ZmqMessage = "hello".into();
assert_eq!(m1.first().map(|b| b.as_ref()), Some(&b"hello"[..]));
// Multi-frame envelope: prepend a header onto a body.
let mut m2 = ZmqMessage::from(b"body".to_vec());
m2.push_front(b"header".to_vec());
assert_eq!(m2.len(), 2);
// Build from any iterator of byte-ish values.
let m3: ZmqMessage = ["a", "b", "c"].into_iter().collect();
assert_eq!(m3.len(), 3);
// Reject empty up front.
let m4 = ZmqMessage::try_from(vec![Bytes::from_static(b"x"), Bytes::from_static(b"y")]).unwrap();
assert_eq!(m4.last().map(|b| b.as_ref()), Some(&b"y"[..]));Implementations§
Source§impl ZmqMessage
impl ZmqMessage
Sourcepub fn push_back(&mut self, frame: impl Into<Bytes>)
pub fn push_back(&mut self, frame: impl Into<Bytes>)
Append a frame to the end of the message.
Accepts anything that converts into Bytes — Vec<u8>, &[u8],
&'static [u8], String, &str, or a Bytes directly.
Sourcepub fn push_front(&mut self, frame: impl Into<Bytes>)
pub fn push_front(&mut self, frame: impl Into<Bytes>)
Prepend a frame at the front of the message.
Accepts anything that converts into Bytes.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, Bytes>
pub fn iter_mut(&mut self) -> IterMut<'_, Bytes>
Iterate over frames in order, allowing mutation. Replacing a frame
is cheap; in-place editing of Bytes is not (it’s an immutable
reference-counted slice — call *frame = new_bytes; to swap).
Sourcepub fn first_mut(&mut self) -> Option<&mut Bytes>
pub fn first_mut(&mut self) -> Option<&mut Bytes>
Mutable reference to the first frame, or None if the message is empty.
Sourcepub fn last_mut(&mut self) -> Option<&mut Bytes>
pub fn last_mut(&mut self) -> Option<&mut Bytes>
Mutable reference to the last frame, or None if the message is empty.
Sourcepub fn pop_front(&mut self) -> Option<Bytes>
pub fn pop_front(&mut self) -> Option<Bytes>
Remove and return the first frame, or None if the message is empty.
Useful for peeling envelope prefixes (e.g. ROUTER identity frames).
Sourcepub fn pop_back(&mut self) -> Option<Bytes>
pub fn pop_back(&mut self) -> Option<Bytes>
Remove and return the last frame, or None if the message is empty.
Sourcepub fn get(&self, index: usize) -> Option<&Bytes>
pub fn get(&self, index: usize) -> Option<&Bytes>
Returns a reference to the frame at index, or None if out of bounds.
Sourcepub fn into_vecdeque(self) -> VecDeque<Bytes>
pub fn into_vecdeque(self) -> VecDeque<Bytes>
Consume the message and return its frames as a VecDeque<Bytes>.
Sourcepub fn prepend(&mut self, message: &ZmqMessage)
pub fn prepend(&mut self, message: &ZmqMessage)
Prepend all frames of message to the front of self, in order.
Sourcepub fn split_off(&mut self, at: usize) -> ZmqMessage
pub fn split_off(&mut self, at: usize) -> ZmqMessage
Split the message at at, returning a new message containing frames
[at..] while self retains [..at].
Trait Implementations§
Source§impl Clone for ZmqMessage
impl Clone for ZmqMessage
Source§fn clone(&self) -> ZmqMessage
fn clone(&self) -> ZmqMessage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ZmqMessage
impl Debug for ZmqMessage
Source§impl Default for ZmqMessage
impl Default for ZmqMessage
Source§fn default() -> ZmqMessage
fn default() -> ZmqMessage
Source§impl<B: Into<Bytes>> Extend<B> for ZmqMessage
impl<B: Into<Bytes>> Extend<B> for ZmqMessage
Source§fn extend<I: IntoIterator<Item = B>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = B>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl From<&[u8]> for ZmqMessage
impl From<&[u8]> for ZmqMessage
Source§impl From<&str> for ZmqMessage
impl From<&str> for ZmqMessage
Source§impl From<Bytes> for ZmqMessage
impl From<Bytes> for ZmqMessage
Source§impl From<String> for ZmqMessage
impl From<String> for ZmqMessage
Source§impl<B: Into<Bytes>> FromIterator<B> for ZmqMessage
impl<B: Into<Bytes>> FromIterator<B> for ZmqMessage
Source§fn from_iter<I: IntoIterator<Item = B>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = B>>(iter: I) -> Self
Collect frames into a ZmqMessage. The resulting message may be
empty if the iterator yielded nothing — most send paths reject
empty messages, so prefer TryFrom<Vec<Bytes>> when you want
the emptiness check up front.