pub struct ConnectionHandle { /* private fields */ }Expand description
Handle for making outgoing RPC calls.
This is the client-side API. It can be cloned and used from multiple tasks.
The actual I/O is driven by the Driver future which must be spawned.
§Example
let (handle, driver) = establish_connection(transport, dispatcher).await?;
tokio::spawn(driver);
// Use handle to make calls
let response = handle.call_raw(method_id, payload).await?;Implementations§
Source§impl ConnectionHandle
impl ConnectionHandle
Sourcepub fn new(
driver_tx: Sender<DriverMessage>,
role: Role,
initial_credit: u32,
) -> Self
pub fn new( driver_tx: Sender<DriverMessage>, role: Role, initial_credit: u32, ) -> Self
Create a new handle for the root connection (conn_id = 0).
All messages (Call/Data/Close/Response) go through a single unified channel to ensure FIFO ordering.
Sourcepub fn new_with_diagnostics(
conn_id: ConnectionId,
driver_tx: Sender<DriverMessage>,
role: Role,
initial_credit: u32,
diagnostic_state: Option<Arc<DiagnosticState>>,
) -> Self
pub fn new_with_diagnostics( conn_id: ConnectionId, driver_tx: Sender<DriverMessage>, role: Role, initial_credit: u32, diagnostic_state: Option<Arc<DiagnosticState>>, ) -> Self
Create a new handle with a specific connection ID and optional diagnostic state.
If diagnostic_state is provided, all RPC calls and channels will be tracked
for debugging purposes.
Sourcepub fn conn_id(&self) -> ConnectionId
pub fn conn_id(&self) -> ConnectionId
Get the connection ID for this handle.
Sourcepub fn diagnostic_state(&self) -> Option<&Arc<DiagnosticState>>
pub fn diagnostic_state(&self) -> Option<&Arc<DiagnosticState>>
Get the diagnostic state, if any.
Sourcepub async fn call<T: Facet<'static>>(
&self,
method_id: u64,
args: &mut T,
) -> Result<ResponseData, TransportError>
pub async fn call<T: Facet<'static>>( &self, method_id: u64, args: &mut T, ) -> Result<ResponseData, TransportError>
Make a typed RPC call with automatic serialization and stream binding.
Walks the args using Poke reflection to find any Rx<T> or Tx<T> fields,
binds stream IDs, and sets up the stream infrastructure before serialization.
§Arguments
method_id- The method ID to callargs- Arguments to serialize (typically a tuple of all method args). Must be mutable so stream IDs can be assigned.
§Stream Binding
For Rx<T> in args (caller passes receiver, keeps sender to push data):
- Allocates a stream ID
- Takes the receiver and spawns a task to drain it, sending Data messages
- The caller keeps the
Tx<T>fromroam::channel()to send values
For Tx<T> in args (caller passes sender, keeps receiver to pull data):
- Allocates a stream ID
- Takes the sender and registers for incoming Data routing
- The caller keeps the
Rx<T>fromroam::channel()to receive values
§Example
// For a streaming method sum(numbers: Rx<i32>) -> i64
let (tx, rx) = roam::channel::<i32>();
let response = handle.call(method_id::SUM, &mut (rx,)).await?;
// tx.send(&42).await to push valuesMake an RPC call with default (empty) metadata.
Sourcepub async fn call_with_metadata<T: Facet<'static>>(
&self,
method_id: u64,
args: &mut T,
metadata: Metadata,
) -> Result<ResponseData, TransportError>
pub async fn call_with_metadata<T: Facet<'static>>( &self, method_id: u64, args: &mut T, metadata: Metadata, ) -> Result<ResponseData, TransportError>
Make an RPC call with custom metadata.
Sourcepub async fn call_raw(
&self,
method_id: u64,
payload: Vec<u8>,
) -> Result<Vec<u8>, TransportError>
pub async fn call_raw( &self, method_id: u64, payload: Vec<u8>, ) -> Result<Vec<u8>, TransportError>
Make a raw RPC call with pre-serialized payload.
Returns the raw response payload bytes.
Note: For streaming calls, use call() which handles channel binding.
Sourcepub async fn call_raw_with_metadata(
&self,
method_id: u64,
payload: Vec<u8>,
metadata: Vec<(String, MetadataValue)>,
) -> Result<Vec<u8>, TransportError>
pub async fn call_raw_with_metadata( &self, method_id: u64, payload: Vec<u8>, metadata: Vec<(String, MetadataValue)>, ) -> Result<Vec<u8>, TransportError>
Make a raw RPC call with pre-serialized payload and metadata.
Returns the raw response payload bytes.
Sourcepub async fn connect(
&self,
metadata: Metadata,
dispatcher: Option<Box<dyn ServiceDispatcher>>,
) -> Result<ConnectionHandle, ConnectError>
pub async fn connect( &self, metadata: Metadata, dispatcher: Option<Box<dyn ServiceDispatcher>>, ) -> Result<ConnectionHandle, ConnectError>
Open a new virtual connection on the link.
Sends a Connect message to the remote peer and waits for an
Accept or Reject response. Returns a new ConnectionHandle
for the virtual connection if accepted.
r[impl core.conn.open]
§Arguments
metadata- Optional metadata to send with the Connect request (e.g., authentication tokens, routing hints).dispatcher- Optional dispatcher for handling incoming requests on the virtual connection. If None, the connection can only make calls, not receive them.
§Example
// Open a new virtual connection that can receive calls
let dispatcher = Box::new(MyDispatcher::new());
let virtual_conn = handle.connect(vec![], Some(dispatcher)).await?;
// Use the new connection for calls
let response = virtual_conn.call_raw(method_id, payload).await?;Sourcepub fn alloc_channel_id(&self) -> ChannelId
pub fn alloc_channel_id(&self) -> ChannelId
Allocate a stream ID for an outgoing stream.
Used internally when binding streams during call().
Sourcepub fn alloc_request_id(&self) -> u64
pub fn alloc_request_id(&self) -> u64
Allocate a unique request ID for an outgoing call.
Used when manually constructing DriverMessage::Call.
Sourcepub fn register_incoming(&self, channel_id: ChannelId, tx: Sender<Vec<u8>>)
pub fn register_incoming(&self, channel_id: ChannelId, tx: Sender<Vec<u8>>)
Register an incoming stream (we receive data from peer).
Used when schema has Tx<T> (callee sends to caller) - we receive that data.
Sourcepub fn register_outgoing_credit(&self, channel_id: ChannelId)
pub fn register_outgoing_credit(&self, channel_id: ChannelId)
Register credit tracking for an outgoing stream.
The actual receiver is owned by the driver, not the registry.
Sourcepub async fn route_data(
&self,
channel_id: ChannelId,
payload: Vec<u8>,
) -> Result<(), ChannelError>
pub async fn route_data( &self, channel_id: ChannelId, payload: Vec<u8>, ) -> Result<(), ChannelError>
Route incoming stream data to the appropriate Rx.
Sourcepub fn close_channel(&self, channel_id: ChannelId)
pub fn close_channel(&self, channel_id: ChannelId)
Close an incoming stream.
Sourcepub fn reset_channel(&self, channel_id: ChannelId)
pub fn reset_channel(&self, channel_id: ChannelId)
Reset a stream.
Sourcepub fn contains_channel(&self, channel_id: ChannelId) -> bool
pub fn contains_channel(&self, channel_id: ChannelId) -> bool
Check if a stream exists.
Sourcepub fn receive_credit(&self, channel_id: ChannelId, bytes: u32)
pub fn receive_credit(&self, channel_id: ChannelId, bytes: u32)
Receive credit for an outgoing stream.
Sourcepub fn driver_tx(&self) -> Sender<DriverMessage>
pub fn driver_tx(&self) -> Sender<DriverMessage>
Get a clone of the driver message sender.
Used for forwarding/proxy scenarios where messages need to be sent on this connection’s wire.
Sourcepub fn bind_response_streams<T: Facet<'static>>(
&self,
response: &mut T,
channels: &[u64],
)
pub fn bind_response_streams<T: Facet<'static>>( &self, response: &mut T, channels: &[u64], )
Bind receivers for Rx<T> streams in a deserialized response.
After deserializing a response, any Rx<T> values are “hollow” - they have
channel IDs but no actual receiver. This method walks the response using
reflection and binds receivers for each Rx<T> so data can be received.
§How it works
For each Rx<T> found in the response:
- Read the channel_id that was set during deserialization
- Create a new channel (tx, rx)
- Set the receiver slot on the Rx
- Register the sender with the channel registry for incoming data routing
This mirrors server-side ChannelRegistry::bind_streams but for responses.
IMPORTANT: The channels parameter contains the authoritative channel IDs
from the Response framing. For forwarded connections (via ForwardingDispatcher),
these IDs may differ from the IDs serialized in the payload. We patch them first.
Trait Implementations§
Source§impl Caller for ConnectionHandle
impl Caller for ConnectionHandle
Source§async fn call_with_metadata<T: Facet<'static> + Send>(
&self,
method_id: u64,
args: &mut T,
metadata: Metadata,
) -> Result<ResponseData, TransportError>
async fn call_with_metadata<T: Facet<'static> + Send>( &self, method_id: u64, args: &mut T, metadata: Metadata, ) -> Result<ResponseData, TransportError>
Source§impl Clone for ConnectionHandle
impl Clone for ConnectionHandle
Source§fn clone(&self) -> ConnectionHandle
fn clone(&self) -> ConnectionHandle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ConnectionHandle
impl RefUnwindSafe for ConnectionHandle
impl Send for ConnectionHandle
impl Sync for ConnectionHandle
impl Unpin for ConnectionHandle
impl UnwindSafe for ConnectionHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more