pub struct RequestContext { /* private fields */ }Expand description
Context passed to request handlers.
Provides methods for sending responses back to the parent. All response methods handle serialization and frame building internally.
§Thread Safety
RequestContext is Clone and can be safely shared across async tasks.
The underlying writer uses a channel-based architecture that eliminates
lock contention.
§Cancellation
Each context has a CancellationToken that is triggered when the parent
sends an ABORT signal. Handlers should check is_cancelled() periodically
or use cancelled().await with tokio::select! for immediate response.
Implementations§
Source§impl RequestContext
impl RequestContext
Sourcepub fn new(method_id: u16, request_id: u32) -> Self
pub fn new(method_id: u16, request_id: u32) -> Self
Create a new request context (for testing without writer).
Sourcepub fn with_writer(
method_id: u16,
request_id: u32,
writer: WriterHandle,
) -> Self
pub fn with_writer( method_id: u16, request_id: u32, writer: WriterHandle, ) -> Self
Create a new request context with a writer.
Sourcepub fn request_id(&self) -> u32
pub fn request_id(&self) -> u32
Get the request ID.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Sourcepub fn cancelled(&self) -> WaitForCancellationFuture<'_>
pub fn cancelled(&self) -> WaitForCancellationFuture<'_>
Sourcepub fn cancellation_token(&self) -> CancellationToken
pub fn cancellation_token(&self) -> CancellationToken
Sourcepub async fn respond<T: Serialize>(&self, payload: &T) -> Result<()>
pub async fn respond<T: Serialize>(&self, payload: &T) -> Result<()>
Send a response with the given payload.
Serializes the payload using MsgPack and sends a response frame.
Sourcepub async fn respond_raw(&self, payload: &[u8]) -> Result<()>
pub async fn respond_raw(&self, payload: &[u8]) -> Result<()>
Send a response with raw bytes (zero-copy).
Sourcepub async fn respond_bytes(&self, payload: Bytes) -> Result<()>
pub async fn respond_bytes(&self, payload: Bytes) -> Result<()>
Send a response with pre-allocated Bytes (zero-copy).
Sourcepub async fn chunk<T: Serialize>(&self, payload: &T) -> Result<()>
pub async fn chunk<T: Serialize>(&self, payload: &T) -> Result<()>
Send a stream chunk.
Serializes the payload using MsgPack and sends a stream chunk frame.
Sourcepub async fn chunk_raw(&self, payload: &[u8]) -> Result<()>
pub async fn chunk_raw(&self, payload: &[u8]) -> Result<()>
Send a stream chunk with raw bytes.
Sourcepub async fn chunk_bytes(&self, payload: Bytes) -> Result<()>
pub async fn chunk_bytes(&self, payload: Bytes) -> Result<()>
Send a stream chunk with pre-allocated Bytes (zero-copy).
Trait Implementations§
Source§impl Clone for RequestContext
impl Clone for RequestContext
Source§fn clone(&self) -> RequestContext
fn clone(&self) -> RequestContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more