Struct ConnectionChannel

Source
pub struct ConnectionChannel<StateType: Debug> { /* private fields */ }
Expand description

The abstraction for handling server connections – here, the connections are provided through a Stream instead of through the TCP/IP API directly. This enables the “Protocol Stack Composition” pattern, as already existing connections may be also added to the Stream (in addition to fresh incoming ones).
When the end-of-stream is reached (possibly due to a “server shutdown” request), the Stream will return None.

Implementations§

Source§

impl<StateType: Debug> ConnectionChannel<StateType>

Source

pub fn new() -> Self

Creates a new instance

Source

pub fn receiver(&mut self) -> Option<Receiver<SocketConnection<StateType>>>

Consumes and returns the tokio::sync::mpsc::Receiver which will be able to provide connections previously sent through Self::feed().
The receiver blocks while there are no connections available and yields None if self is dropped – meaning no more connections will be feed through the channel.

Source

pub async fn feed( &self, socket_connection: SocketConnection<StateType>, ) -> Result<(), ReceiverDroppedErr<SocketConnection<StateType>>>

Delivers connection to the receiver obtained via a call to Self::receiver(), blocking if there are previous connections awaiting delivery

Source

pub fn clone_sender(&self) -> Sender<SocketConnection<StateType>>

Returns a cloned version of the sender.
Notice this method should be considered “advanced”, as keeping a cloned sender will prevent the channel from shutting down, rendering Self::close() useless – currently there is no way for close() to detect this situation.

Source

pub async fn close(self)

Closes the channel (by dropping the sender), causing the receiver produced by [receiver()] to return None, indicating the end-of-stream to the consumer.

Auto Trait Implementations§

§

impl<StateType> Freeze for ConnectionChannel<StateType>

§

impl<StateType> RefUnwindSafe for ConnectionChannel<StateType>

§

impl<StateType> Send for ConnectionChannel<StateType>
where StateType: Send,

§

impl<StateType> Sync for ConnectionChannel<StateType>
where StateType: Send,

§

impl<StateType> Unpin for ConnectionChannel<StateType>

§

impl<StateType> UnwindSafe for ConnectionChannel<StateType>

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<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V