Skip to main content

MessagePayload

Enum MessagePayload 

Source
pub enum MessagePayload {
    Local(Box<dyn Any + Send>),
    Serialized(Bytes),
}
Expand description

The payload carried alongside an Envelope.

Local is used for same-core delivery with zero serialization. Serialized carries an opaque byte buffer for cross-core or cross-engine delivery.

Variants§

§

Local(Box<dyn Any + Send>)

§

Serialized(Bytes)

Implementations§

Source§

impl MessagePayload

Source

pub fn local<M: Send + 'static>(msg: M) -> Self

Source

pub fn serialized(bytes: impl Into<Bytes>) -> Self

Source

pub fn downcast_owned<T: Send + 'static>(self) -> Option<T>

Consume the payload and extract an owned value of type T.

Returns None if the payload is Serialized or the stored value is not of type T.

Source

pub fn extract<M: Message>(&self) -> Result<&M, PayloadError>

Typed access to a Local payload. Returns PayloadError::TypeMismatch if the stored value is not of type M, or PayloadError::WrongVariant if the payload is Serialized.

Source

pub fn downcast_ref<M: 'static>(&self) -> Option<&M>

Source

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

Source

pub fn into_serialized(self) -> Option<Bytes>

Source

pub fn payload_len(&self) -> u32

Meaningful only for Serialized; returns 0 for Local.

Trait Implementations§

Source§

impl Debug for MessagePayload

Source§

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

Formats the value using the given formatter. Read more

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