RingMessage

Trait RingMessage 

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§

fn message_type() -> u64

Get the message type discriminator.

fn message_id(&self) -> MessageId

Get the message ID.

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

Serialize the message to bytes.

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

Deserialize a message from bytes.

Provided Methods§

fn correlation_id(&self) -> CorrelationId

Get the correlation ID (if any).

fn priority(&self) -> Priority

Get the priority.

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§