Struct Connection

Source
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,

Source

pub fn new(socket: S) -> Self

Create a new connection.

Source

pub fn read(&self) -> &ReadConnection<S::ReadHalf>

The reference to the read half of the connection.

Source

pub fn read_mut(&mut self) -> &mut ReadConnection<S::ReadHalf>

The mutable reference to the read half of the connection.

Source

pub fn write(&self) -> &WriteConnection<S::WriteHalf>

The reference to the write half of the connection.

Source

pub fn write_mut(&mut self) -> &mut WriteConnection<S::WriteHalf>

The mutable reference to the write half of the connection.

Source

pub fn split( self, ) -> (ReadConnection<S::ReadHalf>, WriteConnection<S::WriteHalf>)

Split the connection into read and write halves.

Source

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).

Source

pub fn id(&self) -> usize

The unique identifier of the connection.

Source

pub async fn send_call<Method>(&mut self, call: &Call<Method>) -> Result<()>
where Method: Serialize + Debug,

Sends a method call.

Convenience wrapper around WriteConnection::send_call.

Source

pub async fn receive_reply<'r, Params, ReplyError>( &'r mut self, ) -> Result<Result<Reply<Params>, ReplyError>>
where Params: Deserialize<'r> + Debug, ReplyError: Deserialize<'r> + Debug,

Receives a method call reply.

Convenience wrapper around ReadConnection::receive_reply.

Source

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.

Source

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.

Source

pub async fn send_reply<Params>(&mut self, reply: &Reply<Params>) -> Result<()>
where Params: Serialize + Debug,

Send a reply over the socket.

Convenience wrapper around WriteConnection::send_reply.

Source

pub async fn send_error<ReplyError>(&mut self, error: &ReplyError) -> Result<()>
where ReplyError: Serialize + Debug,

Send an error reply over the socket.

Convenience wrapper around WriteConnection::send_error.

Trait Implementations§

Source§

impl<S: Debug + Socket> Debug for Connection<S>
where S::ReadHalf: Debug, S::WriteHalf: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S> From<S> for Connection<S>
where S: Socket,

Source§

fn from(socket: S) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<S> Freeze for Connection<S>
where <S as Socket>::ReadHalf: Freeze, <S as Socket>::WriteHalf: Freeze,

§

impl<S> RefUnwindSafe for Connection<S>

§

impl<S> Send for Connection<S>
where <S as Socket>::ReadHalf: Send, <S as Socket>::WriteHalf: Send,

§

impl<S> Sync for Connection<S>
where <S as Socket>::ReadHalf: Sync, <S as Socket>::WriteHalf: Sync,

§

impl<S> Unpin for Connection<S>
where <S as Socket>::ReadHalf: Unpin, <S as Socket>::WriteHalf: Unpin,

§

impl<S> UnwindSafe for Connection<S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more