Skip to main content

ZmqMessage

Struct ZmqMessage 

Source
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

Source

pub fn push_back(&mut self, frame: impl Into<Bytes>)

Append a frame to the end of the message.

Accepts anything that converts into BytesVec<u8>, &[u8], &'static [u8], String, &str, or a Bytes directly.

Source

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.

Source

pub fn iter(&self) -> Iter<'_, Bytes>

Iterate over frames in order.

Source

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).

Source

pub fn first(&self) -> Option<&Bytes>

First frame, or None if the message is empty.

Source

pub fn last(&self) -> Option<&Bytes>

Last frame, or None if the message is empty.

Source

pub fn first_mut(&mut self) -> Option<&mut Bytes>

Mutable reference to the first frame, or None if the message is empty.

Source

pub fn last_mut(&mut self) -> Option<&mut Bytes>

Mutable reference to the last frame, or None if the message is empty.

Source

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).

Source

pub fn pop_back(&mut self) -> Option<Bytes>

Remove and return the last frame, or None if the message is empty.

Source

pub fn len(&self) -> usize

Number of frames in the message.

Source

pub fn is_empty(&self) -> bool

Returns true if the message contains no frames.

Source

pub fn get(&self, index: usize) -> Option<&Bytes>

Returns a reference to the frame at index, or None if out of bounds.

Source

pub fn into_vec(self) -> Vec<Bytes>

Consume the message and return its frames as a Vec<Bytes>.

Source

pub fn into_vecdeque(self) -> VecDeque<Bytes>

Consume the message and return its frames as a VecDeque<Bytes>.

Source

pub fn prepend(&mut self, message: &ZmqMessage)

Prepend all frames of message to the front of self, in order.

Source

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

Source§

fn clone(&self) -> ZmqMessage

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ZmqMessage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ZmqMessage

Source§

fn default() -> ZmqMessage

Returns the “default value” for a type. Read more
Source§

impl<B: Into<Bytes>> Extend<B> for ZmqMessage

Source§

fn extend<I: IntoIterator<Item = B>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl From<&[u8]> for ZmqMessage

Source§

fn from(b: &[u8]) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for ZmqMessage

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Bytes> for ZmqMessage

Source§

fn from(b: Bytes) -> Self

Converts to this type from the input type.
Source§

impl From<String> for ZmqMessage

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for ZmqMessage

Source§

fn from(v: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl<B: Into<Bytes>> FromIterator<B> for ZmqMessage

Source§

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.

Source§

impl Hash for ZmqMessage

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Index<usize> for ZmqMessage

Source§

fn index(&self, index: usize) -> &Self::Output

Indexed access to a frame. Panics on out-of-bounds; use get for the checked variant.

Source§

type Output = Bytes

The returned type after indexing.
Source§

impl<'a> IntoIterator for &'a ZmqMessage

Source§

type Item = &'a Bytes

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, Bytes>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a mut ZmqMessage

Source§

type Item = &'a mut Bytes

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, Bytes>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for ZmqMessage

Source§

type Item = Bytes

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<[Bytes; 2]>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for ZmqMessage

Source§

fn eq(&self, other: &ZmqMessage) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<Vec<Bytes>> for ZmqMessage

Source§

type Error = ZmqEmptyMessageError

The type returned in the event of a conversion error.
Source§

fn try_from(v: Vec<Bytes>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<VecDeque<Bytes>> for ZmqMessage

Source§

type Error = ZmqEmptyMessageError

The type returned in the event of a conversion error.
Source§

fn try_from(v: VecDeque<Bytes>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<ZmqMessage> for Bytes

Source§

type Error = MessageConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(z: ZmqMessage) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<ZmqMessage> for String

Source§

type Error = MessageConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(z: ZmqMessage) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<ZmqMessage> for Vec<u8>

Source§

type Error = MessageConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(z: ZmqMessage) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for ZmqMessage

Source§

impl StructuralPartialEq for ZmqMessage

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.