pub trait IpcConnection:
Send
+ Sync
+ 'static {
// Required methods
fn connect(
endpoint: &str,
) -> impl Future<Output = Result<Self, Error>> + Send
where Self: Sized;
fn peer_endpoint(&self) -> &str;
fn close(&mut self) -> IoFuture<'_, ()>;
fn send(&mut self, buf: Bytes) -> IoFuture<'_, ()>;
fn recv(&mut self) -> IoFuture<'_, Bytes>;
}Expand description
Describes the behavior of an IPC connection.
An IPC connection should be a duplex communication channel between two end points. If the underlying protocol is not duplex, the implementation should simulate the duplex behavior, e.g., by using two separate connections.
Implementations are responsible for message framing: one call to send must
correspond to exactly one call to recv on the remote end, regardless of how
the underlying transport delivers bytes.
Required Methods§
Sourcefn connect(endpoint: &str) -> impl Future<Output = Result<Self, Error>> + Sendwhere
Self: Sized,
fn connect(endpoint: &str) -> impl Future<Output = Result<Self, Error>> + Sendwhere
Self: Sized,
Connects to an IPC listener at a specific endpoint.
This is a constructor-style method that returns a concrete connection, so it requires
Self: Sized.
Sourcefn peer_endpoint(&self) -> &str
fn peer_endpoint(&self) -> &str
Returns the peer endpoint of the IPC connection.
Sourcefn send(&mut self, buf: Bytes) -> IoFuture<'_, ()>
fn send(&mut self, buf: Bytes) -> IoFuture<'_, ()>
Sends a message to the other end of the connection.
The entire buf is delivered as a single framed message.
Sourcefn recv(&mut self) -> IoFuture<'_, Bytes>
fn recv(&mut self) -> IoFuture<'_, Bytes>
Receives the next message from the other end of the connection.
Returns the message payload as a Bytes value; implementations should return a slice
of their internal read buffer whenever possible to avoid copying.
§Cancel safety
The implementation should be cancel safe. If the method is used as the event in a
tokio::select! statement and some other branch completes first, then
it is guaranteed that no data was read from the underlying connection.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl IpcConnection for PipeConnection
pipe only.impl IpcConnection for WebSocketConnection
websocket only.