pub struct Message { /* private fields */ }Expand description
A multi-part message, comprising a message body and a list of parts. Messages only contain references to underlying byte buffers and are cheaply cloned.
Implementations§
Source§impl Message
impl Message
Sourcepub fn from_body_and_parts(body: Part, parts: Vec<Part>) -> Self
pub fn from_body_and_parts(body: Part, parts: Vec<Part>) -> Self
Returns a new message with the given body and parts.
Sourcepub fn num_parts(&self) -> usize
pub fn num_parts(&self) -> usize
Returns the total number of parts (excluding the body) in the message.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether the message is empty. It is always false, since the body is always defined.
Sourcepub fn into_inner(self) -> (Part, Vec<Part>)
pub fn into_inner(self) -> (Part, Vec<Part>)
Convert this message into its constituent components.
Sourcepub fn visit_parts_mut<T, E>(
&mut self,
f: impl FnMut(&mut T) -> Result<(), E>,
) -> Result<(), E>
pub fn visit_parts_mut<T, E>( &mut self, f: impl FnMut(&mut T) -> Result<(), E>, ) -> Result<(), E>
Visit every typed part containing a T-typed value.
Sourcepub fn frame_len(&self) -> usize
pub fn frame_len(&self) -> usize
Returns the total size (in bytes) of the message when it is framed.
Sourcepub fn framed(self) -> Frame
pub fn framed(self) -> Frame
Efficiently frames a message containing the body and all of its parts using a simple frame-length encoding:
+--------------------+-------------------+--------------------+-------------------+ ... +
| body_tag (u64 BE) | body bytes | part1_tag (u64 BE) | part1 bytes | |
+--------------------+-------------------+--------------------+-------------------+ +
repeat
for
each partThe high bit of each tag indicates whether the part is typed. If set,
the lower 63 bits hold the part length, and the tag is followed by the
part typehash as a u64 BE before the part bytes.
Sourcepub fn from_framed(buf: Bytes) -> Result<Self, Error>
pub fn from_framed(buf: Bytes) -> Result<Self, Error>
Reassembles a message from a framed encoding.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Message
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Message
impl UnwindSafe for Message
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more