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§
Implementations§
Source§impl MessagePayload
impl MessagePayload
pub fn local<M: Send + 'static>(msg: M) -> Self
pub fn serialized(bytes: impl Into<Bytes>) -> Self
Sourcepub fn downcast_owned<T: Send + 'static>(self) -> Option<T>
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.
Sourcepub fn extract<M: Message>(&self) -> Result<&M, PayloadError>
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.
pub fn downcast_ref<M: 'static>(&self) -> Option<&M>
pub fn as_serialized(&self) -> Option<&Bytes>
pub fn into_serialized(self) -> Option<Bytes>
Sourcepub fn payload_len(&self) -> u32
pub fn payload_len(&self) -> u32
Meaningful only for Serialized; returns 0 for Local.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for MessagePayload
impl !RefUnwindSafe for MessagePayload
impl Send for MessagePayload
impl !Sync for MessagePayload
impl Unpin for MessagePayload
impl UnsafeUnpin for MessagePayload
impl !UnwindSafe for MessagePayload
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