pub struct Connection<S: Socket> { /* private fields */ }
Expand description
A connection.
The low-level API to send and receive messages.
Each connection gets a unique identifier when created that can be queried using
Connection::id
. This ID is shared betwen the read and write halves of the connection. It
can be used to associate the read and write halves of the same connection.
§Cancel safety
All async methods of this type are cancel safe unless explicitly stated otherwise in its documentation.
Implementations§
Source§impl<S> Connection<S>where
S: Socket,
impl<S> Connection<S>where
S: Socket,
Sourcepub fn read(&self) -> &ReadConnection<S::ReadHalf>
pub fn read(&self) -> &ReadConnection<S::ReadHalf>
The reference to the read half of the connection.
Sourcepub fn read_mut(&mut self) -> &mut ReadConnection<S::ReadHalf>
pub fn read_mut(&mut self) -> &mut ReadConnection<S::ReadHalf>
The mutable reference to the read half of the connection.
Sourcepub fn write(&self) -> &WriteConnection<S::WriteHalf>
pub fn write(&self) -> &WriteConnection<S::WriteHalf>
The reference to the write half of the connection.
Sourcepub fn write_mut(&mut self) -> &mut WriteConnection<S::WriteHalf>
pub fn write_mut(&mut self) -> &mut WriteConnection<S::WriteHalf>
The mutable reference to the write half of the connection.
Sourcepub fn split(
self,
) -> (ReadConnection<S::ReadHalf>, WriteConnection<S::WriteHalf>)
pub fn split( self, ) -> (ReadConnection<S::ReadHalf>, WriteConnection<S::WriteHalf>)
Split the connection into read and write halves.
Sourcepub fn join(
read: ReadConnection<S::ReadHalf>,
write: WriteConnection<S::WriteHalf>,
) -> Self
pub fn join( read: ReadConnection<S::ReadHalf>, write: WriteConnection<S::WriteHalf>, ) -> Self
Join the read and write halves into a connection (the opposite of Connection::split
).
Sourcepub async fn send_call<Method>(&mut self, call: &Call<Method>) -> Result<()>
pub async fn send_call<Method>(&mut self, call: &Call<Method>) -> Result<()>
Sends a method call.
Convenience wrapper around WriteConnection::send_call
.
Sourcepub async fn receive_reply<'r, Params, ReplyError>(
&'r mut self,
) -> Result<Result<Reply<Params>, ReplyError>>
pub async fn receive_reply<'r, Params, ReplyError>( &'r mut self, ) -> Result<Result<Reply<Params>, ReplyError>>
Receives a method call reply.
Convenience wrapper around ReadConnection::receive_reply
.
Sourcepub async fn call_method<'r, Method, ReplyError, Params>(
&'r mut self,
call: &Call<Method>,
) -> Result<Result<Reply<Params>, ReplyError>>where
Method: Serialize + Debug,
Params: Deserialize<'r> + Debug,
ReplyError: Deserialize<'r> + Debug,
pub async fn call_method<'r, Method, ReplyError, Params>(
&'r mut self,
call: &Call<Method>,
) -> Result<Result<Reply<Params>, ReplyError>>where
Method: Serialize + Debug,
Params: Deserialize<'r> + Debug,
ReplyError: Deserialize<'r> + Debug,
Call a method and receive a reply.
This is a convenience method that combines Connection::send_call
and
Connection::receive_reply
.
Sourcepub async fn receive_call<'m, Method>(&'m mut self) -> Result<Call<Method>>where
Method: Deserialize<'m> + Debug,
pub async fn receive_call<'m, Method>(&'m mut self) -> Result<Call<Method>>where
Method: Deserialize<'m> + Debug,
Receive a method call over the socket.
Convenience wrapper around ReadConnection::receive_call
.
Sourcepub async fn send_reply<Params>(&mut self, reply: &Reply<Params>) -> Result<()>
pub async fn send_reply<Params>(&mut self, reply: &Reply<Params>) -> Result<()>
Send a reply over the socket.
Convenience wrapper around WriteConnection::send_reply
.
Sourcepub async fn send_error<ReplyError>(&mut self, error: &ReplyError) -> Result<()>
pub async fn send_error<ReplyError>(&mut self, error: &ReplyError) -> Result<()>
Send an error reply over the socket.
Convenience wrapper around WriteConnection::send_error
.