pub trait Transport {
type Error: Clone + Error + Send + Sync + 'static;
type Shared: Send + Sync;
type Exclusive: Send;
type SendBuffer: Encoder + Send;
type SendFutureState: Send;
type RecvFutureState: Send;
type RecvBuffer: Decoder + Send;
// Required methods
fn split(self) -> (Self::Shared, Self::Exclusive);
fn acquire(shared: &Self::Shared) -> Self::SendBuffer;
fn begin_send(
shared: &Self::Shared,
buffer: Self::SendBuffer,
) -> Self::SendFutureState;
fn poll_send(
future: Pin<&mut Self::SendFutureState>,
cx: &mut Context<'_>,
shared: &Self::Shared,
) -> Poll<Result<(), Option<Self::Error>>>;
fn begin_recv(
shared: &Self::Shared,
exclusive: &mut Self::Exclusive,
) -> Self::RecvFutureState;
fn poll_recv(
future: Pin<&mut Self::RecvFutureState>,
cx: &mut Context<'_>,
shared: &Self::Shared,
exclusive: &mut Self::Exclusive,
) -> Poll<Result<Self::RecvBuffer, Option<Self::Error>>>;
}Expand description
A transport backend which can send and receive messages.
§Terminology
Note that this trait does not correspond directly with the FIDL notion of a transport. For clarity, implementors of this trait should be called “transport backends”, as they are specific implementations of the more general notion of a “transport” in FIDL.
In FIDL, protocols can be assigned a “transport” such as “Channel” or “Driver”. The choice of transport for a protocol controls the concrete types used for client ends and server ends of that protocol. A protocol with “Channel” transport will have client and server ends that are Zircon channels; a protocol with “Driver” transport will have client and server ends that are Driver channels.
All transport backends must be able to send and receive buffers of bytes. In addition to those bytes, transport backends may also support sending and receiving resource types like Zircon and Driver handles with those bytes. The additional resource types a transport backend supports defines which protocols can be run over that transport backend: a protocol can be run over a transport backend if all of the resource types its messages may contain can be sent and received using that transport backend. This may or may not have a correlation with the FIDL transport of that protocol.
§Implementation
The futures provided by this trait should be cancel-safe, which constrains their behavior:
- Operations should not partially complete.
- Operations should only complete during polling.
SendFuture should return Poll::Ready with an error when polled after the
transport backend is closed.
Required Associated Types§
The shared part of the transport backend. It is provided by shared reference while sending and receiving. For an MPSC, this would contain a sender.
Sourcetype Exclusive: Send
type Exclusive: Send
The exclusive part of the transport backend. It is provided by mutable reference only while receiving. For an MPSC, this would contain a receiver.
Sourcetype SendBuffer: Encoder + Send
type SendBuffer: Encoder + Send
The buffer type for sending.
Sourcetype SendFutureState: Send
type SendFutureState: Send
The future state for send operations.
Sourcetype RecvFutureState: Send
type RecvFutureState: Send
The future state for receive operations.
Sourcetype RecvBuffer: Decoder + Send
type RecvBuffer: Decoder + Send
The buffer type for receivers.
Required Methods§
Sourcefn split(self) -> (Self::Shared, Self::Exclusive)
fn split(self) -> (Self::Shared, Self::Exclusive)
Splits the transport backend into shared and exclusive pieces.
Sourcefn acquire(shared: &Self::Shared) -> Self::SendBuffer
fn acquire(shared: &Self::Shared) -> Self::SendBuffer
Acquires an empty send buffer for the transport backend.
Sourcefn begin_send(
shared: &Self::Shared,
buffer: Self::SendBuffer,
) -> Self::SendFutureState
fn begin_send( shared: &Self::Shared, buffer: Self::SendBuffer, ) -> Self::SendFutureState
Begins sending a SendBuffer over this transport backend.
Returns the state for a future which can be polled with poll_send.
Sourcefn poll_send(
future: Pin<&mut Self::SendFutureState>,
cx: &mut Context<'_>,
shared: &Self::Shared,
) -> Poll<Result<(), Option<Self::Error>>>
fn poll_send( future: Pin<&mut Self::SendFutureState>, cx: &mut Context<'_>, shared: &Self::Shared, ) -> Poll<Result<(), Option<Self::Error>>>
Polls a SendFutureState for completion with the shared part of the
transport backend.
When ready, polling returns one of three values:
Ok(())if the buffer was successfully sent.Err(None)if the connection was terminated normally (e.g. withPEER_CLOSED).Err(Some(error))if the connection was terminated abnormally.
Sourcefn begin_recv(
shared: &Self::Shared,
exclusive: &mut Self::Exclusive,
) -> Self::RecvFutureState
fn begin_recv( shared: &Self::Shared, exclusive: &mut Self::Exclusive, ) -> Self::RecvFutureState
Begins receiving a RecvBuffer over this transport backend.
Returns the state for a future which can be polled with poll_recv.
Sourcefn poll_recv(
future: Pin<&mut Self::RecvFutureState>,
cx: &mut Context<'_>,
shared: &Self::Shared,
exclusive: &mut Self::Exclusive,
) -> Poll<Result<Self::RecvBuffer, Option<Self::Error>>>
fn poll_recv( future: Pin<&mut Self::RecvFutureState>, cx: &mut Context<'_>, shared: &Self::Shared, exclusive: &mut Self::Exclusive, ) -> Poll<Result<Self::RecvBuffer, Option<Self::Error>>>
Polls a RecvFutureState for completion with a receiver.
When ready, polling returns one of three values:
Ok(buffer)ifbufferwas successfully received.Err(None)if the connection was terminated normally (e.g. withPEER_CLOSED).Err(Some(error))if the connection was terminated abnormally.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.