Trait Transport
pub trait Transport: Send + 'static {
type Error: Error + Send + Sync + 'static;
// Required methods
fn connect<'life0, 'life1, 'async_trait>(
&'life0 mut self,
url: &'life1 str,
headers: Vec<(String, String)>,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn send<'life0, 'async_trait>(
&'life0 mut self,
data: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn recv<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn close<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
// Provided method
fn close_reason(&self) -> Option<String> { ... }
}Expand description
A bidirectional message transport.
The default is WebSocket (TungsteniteTransport); MockTransport enables
unit testing without a real server.
§Implementors
TungsteniteTransport– Production WebSocket transport usingtokio-tungstenite. Handles both Text and Binary frames (Vertex AI sends Binary).MockTransport– Deterministic test transport. Records sent data and replays scripted responses. When the queue is empty,recv()pends indefinitely.
Required Associated Types§
Required Methods§
fn connect<'life0, 'life1, 'async_trait>(
&'life0 mut self,
url: &'life1 str,
headers: Vec<(String, String)>,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn connect<'life0, 'life1, 'async_trait>(
&'life0 mut self,
url: &'life1 str,
headers: Vec<(String, String)>,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Connect to the given URL with optional headers.
fn send<'life0, 'async_trait>(
&'life0 mut self,
data: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn send<'life0, 'async_trait>(
&'life0 mut self,
data: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Send raw bytes.
Provided Methods§
fn close_reason(&self) -> Option<String>
fn close_reason(&self) -> Option<String>
Why the peer closed the connection, if it said.
Read after recv returns Ok(None). A server-initiated
close on the Live API carries a status code and a reason — a context
window exhausted, an invalid argument, a quota — and without this the
only thing that survives is the fact of the close. That is the difference
between a session that “just dropped” and one that dropped for a stated
reason: a governed voice evaluation lost several turns to a close whose
reason had been logged at warn and then discarded, so it was never
diagnosed.
Defaults to None so an existing transport implementation keeps
compiling; it merely reports nothing.