Trait PersistentMessage
pub trait PersistentMessage: Sized + RingMessage {
// Required methods
fn handler_id() -> u32;
fn to_inline_payload(&self) -> Option<[u8; 32]>;
fn from_inline_payload(payload: &[u8]) -> Result<Self, RingKernelError>;
fn payload_size() -> usize;
// Provided methods
fn requires_response() -> bool { ... }
fn can_inline() -> bool { ... }
}Expand description
Trait for messages that can be dispatched within a persistent GPU kernel.
This trait extends RingMessage with additional metadata needed for
type-based dispatch within a unified kernel. Each message type is
associated with a handler ID that maps to a CUDA device function.
§Implementation
Use the #[derive(PersistentMessage)] macro for automatic implementation:
#[derive(RingMessage, PersistentMessage)]
#[message(type_id = 1001)]
#[persistent_message(handler_id = 1, requires_response = true)]
pub struct FraudCheckRequest {
pub transaction_id: u64,
pub amount: f32,
pub account_id: u32,
}Required Methods§
fn handler_id() -> u32
fn handler_id() -> u32
Handler ID for CUDA dispatch (0-255).
This maps to a case in the generated switch statement:
switch (msg->handler_id) {
case 1: handle_fraud_check(msg, state, response); break;
// ...
}fn to_inline_payload(&self) -> Option<[u8; 32]>
fn to_inline_payload(&self) -> Option<[u8; 32]>
Convert message to inline payload bytes.
Returns Some([u8; 32]) if the message fits in 32 bytes,
None if the message requires external buffer allocation.
fn from_inline_payload(payload: &[u8]) -> Result<Self, RingKernelError>
fn from_inline_payload(payload: &[u8]) -> Result<Self, RingKernelError>
Reconstruct message from inline payload bytes.
§Errors
Returns error if the payload is invalid or incomplete.
fn payload_size() -> usize
fn payload_size() -> usize
Get the serialized payload size in bytes.
Provided Methods§
fn requires_response() -> bool
fn requires_response() -> bool
Whether this message type expects a response.
When true, the kernel will generate a response message after
processing. The caller should use poll_typed::<ResponseType>()
to retrieve responses.
fn can_inline() -> bool
fn can_inline() -> bool
Check if this message type can be inlined (fits in 32 bytes).
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.