RingMessage

Trait RingMessage 

Source
pub trait RingMessage:
    Send
    + Sync
    + 'static {
    // Required methods
    fn message_type() -> u64;
    fn message_id(&self) -> MessageId;
    fn serialize(&self) -> Vec<u8> ;
    fn deserialize(bytes: &[u8]) -> Result<Self, RingKernelError>
       where Self: Sized;

    // Provided methods
    fn correlation_id(&self) -> CorrelationId { ... }
    fn priority(&self) -> Priority { ... }
    fn size_hint(&self) -> usize
       where Self: Sized { ... }
}
Expand description

Trait for types that can be sent as kernel messages.

This trait is typically implemented via the #[derive(RingMessage)] macro.

§Example

#[derive(RingMessage)]
struct MyRequest {
    #[message(id)]
    id: MessageId,
    data: Vec<f32>,
}

Required Methods§

Source

fn message_type() -> u64

Get the message type discriminator.

Source

fn message_id(&self) -> MessageId

Get the message ID.

Source

fn serialize(&self) -> Vec<u8>

Serialize the message to bytes.

Source

fn deserialize(bytes: &[u8]) -> Result<Self, RingKernelError>
where Self: Sized,

Deserialize a message from bytes.

Provided Methods§

Source

fn correlation_id(&self) -> CorrelationId

Get the correlation ID (if any).

Source

fn priority(&self) -> Priority

Get the priority.

Source

fn size_hint(&self) -> usize
where Self: Sized,

Get the serialized size hint.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§