Connection

Struct Connection 

Source
pub struct Connection<Bindings: ConnectionBindings> { /* private fields */ }
Expand description

A bidirectional, message-oriented AsyncRead/AsyncWrite stream wrapper.

Connections are Futures that you spawn. To send messages, you push them into the outbound message stream. To receive messages, you implement a MessageReactor.

Inbound messages are not wrapped in a Stream, in order to avoid an extra layer of async buffering. If you need to buffer messages or forward them to a Stream, you can do so in the reactor. If you can process them very quickly, you can handle them inline in the reactor callback on_messages, which will let you reply as soon as possible.

Implementations§

Source§

impl<Bindings: ConnectionBindings> Connection<Bindings>
where <Bindings::Deserializer as Deserializer>::Message: Send,

Source

pub fn new( stream: Bindings::Stream, address: SocketAddr, deserializer: Bindings::Deserializer, serializer: Bindings::Serializer, max_buffer_length: usize, buffer_allocation_increment: usize, max_queued_send_messages: usize, outbound_messages: Receiver<<Bindings::Serializer as Serializer>::Message>, reactor: Bindings::Reactor, ) -> Connection<Bindings>

Create a new protosocket Connection with the given stream and reactor.

Probably you are interested in the protosocket-server or protosocket-prost crates.

Trait Implementations§

Source§

impl<Bindings: ConnectionBindings> Display for Connection<Bindings>

Source§

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

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

impl<Lifecycle: ConnectionBindings> Drop for Connection<Lifecycle>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<Bindings: ConnectionBindings> Future for Connection<Bindings>

Source§

fn poll(self: Pin<&mut Self>, context: &mut Context<'_>) -> Poll<Self::Output>

Take a look at ConnectionBindings for the type definitions used by the Connection

This method performs the following steps:

  1. Check for read readiness and read into the receive_buffer (up to max_buffer_length).
  2. Deserialize the read bytes into Messages and store them in the inbound_messages queue.
  3. Dispatch messages as they are deserialized using the user-provided MessageReactor.
  4. Serialize messages from outbound_messages queue, up to max_queued_send_messages.
  5. Send serialized messages.
Source§

type Output = ()

The type of value produced on completion.
Source§

impl<Bindings: ConnectionBindings> Unpin for Connection<Bindings>

Auto Trait Implementations§

§

impl<Bindings> Freeze for Connection<Bindings>

§

impl<Bindings> RefUnwindSafe for Connection<Bindings>

§

impl<Bindings> Send for Connection<Bindings>

§

impl<Bindings> Sync for Connection<Bindings>

§

impl<Bindings> UnwindSafe for Connection<Bindings>

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, 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<F> IntoFuture for F
where F: Future,

Source§

type Output = <F as Future>::Output

The output that the future will produce on completion.
Source§

type IntoFuture = F

Which kind of future are we turning this into?
Source§

fn into_future(self) -> <F as IntoFuture>::IntoFuture

Creates a future from a value. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.