Skip to main content

Transport

Trait Transport 

Source
pub trait Transport {
    // Required methods
    fn send(
        &mut self,
        cx: &Cx,
        message: &JsonRpcMessage,
    ) -> Result<(), TransportError>;
    fn recv(&mut self, cx: &Cx) -> Result<JsonRpcMessage, TransportError>;
    fn close(&mut self) -> Result<(), TransportError>;

    // Provided methods
    fn send_request(
        &mut self,
        cx: &Cx,
        request: &JsonRpcRequest,
    ) -> Result<(), TransportError> { ... }
    fn send_response(
        &mut self,
        cx: &Cx,
        response: &JsonRpcResponse,
    ) -> Result<(), TransportError> { ... }
}
Expand description

Transport trait for cancel-correct message passing.

All transports must integrate with asupersync’s capability context (Cx) for cancellation checking and budget enforcement.

§Cancel-Safety

Implementations should:

  • Call cx.checkpoint() before blocking operations
  • Use two-phase patterns (reserve/commit) where applicable
  • Respect budget constraints from the context

§Example

impl Transport for MyTransport {
    fn send(&mut self, cx: &Cx, msg: &JsonRpcMessage) -> Result<(), TransportError> {
        cx.checkpoint()?;  // Check for cancellation
        let bytes = self.codec.encode(msg)?;
        self.write_all(&bytes)?;
        Ok(())
    }
}

Required Methods§

Source

fn send( &mut self, cx: &Cx, message: &JsonRpcMessage, ) -> Result<(), TransportError>

Send a JSON-RPC message through this transport.

§Cancel-Safety

This operation checks for cancellation before sending. If cancelled, the message is not sent.

§Errors

Returns an error if the transport is closed, an I/O error occurs, or the request has been cancelled.

Source

fn recv(&mut self, cx: &Cx) -> Result<JsonRpcMessage, TransportError>

Receive the next JSON-RPC message from this transport.

§Cancel-Safety

This operation checks for cancellation while waiting for data. If cancelled, returns TransportError::Cancelled.

§Errors

Returns an error if the transport is closed, an I/O error occurs, or the request has been cancelled.

Source

fn close(&mut self) -> Result<(), TransportError>

Close the transport gracefully.

This flushes any pending data and releases resources.

Provided Methods§

Source

fn send_request( &mut self, cx: &Cx, request: &JsonRpcRequest, ) -> Result<(), TransportError>

Send a request through this transport.

Convenience method that wraps a request in a message.

Source

fn send_response( &mut self, cx: &Cx, response: &JsonRpcResponse, ) -> Result<(), TransportError>

Send a response through this transport.

Convenience method that wraps a response in a message.

Implementors§

Source§

impl Transport for StreamableHttpTransport

Source§

impl Transport for AsyncStdioTransport

Source§

impl Transport for MemoryTransport

Source§

impl<R, W> Transport for HttpTransport<R, W>
where R: Read, W: Write,

Source§

impl<R, W> Transport for SseClientTransport<R, W>
where R: Read, W: Write,

Source§

impl<R, W> Transport for WsClientTransport<R, W>
where R: Read, W: Write,

Source§

impl<R, W> Transport for WsTransport<R, W>
where R: Read, W: Write,

Source§

impl<R, W> Transport for StdioTransport<R, W>
where R: Read, W: Write,

Source§

impl<W, R> Transport for SseServerTransport<W, R>
where W: Write, R: Iterator<Item = JsonRpcRequest>,