Skip to main content

CoreAdapter

Trait CoreAdapter 

Source
pub trait CoreAdapter<E: SocketEmitter>:
    Sized
    + Send
    + Sync
    + 'static {
    type Error: StdError + Into<AdapterError> + Send + 'static;
    type State: Send + Sync + 'static;
    type AckStream: Stream<Item = AckStreamItem<E::AckError>> + FusedStream + Send + 'static;
    type InitRes: Spawnable + Send;

    // Required methods
    fn new(state: &Self::State, local: CoreLocalAdapter<E>) -> Self;
    fn init(
        self: Arc<Self>,
        on_success: impl FnOnce() + Send + 'static,
    ) -> Self::InitRes;
    fn broadcast_with_ack(
        &self,
        packet: Packet,
        opts: BroadcastOptions,
        timeout: Option<Duration>,
    ) -> impl Future<Output = Result<Self::AckStream, Self::Error>> + Send;
    fn get_local(&self) -> &CoreLocalAdapter<E>;

    // Provided methods
    fn close(&self) -> impl Future<Output = Result<(), Self::Error>> + Send { ... }
    fn server_count(
        &self,
    ) -> impl Future<Output = Result<u16, Self::Error>> + Send { ... }
    fn broadcast(
        &self,
        packet: Packet,
        opts: BroadcastOptions,
    ) -> impl Future<Output = Result<(), BroadcastError>> + Send { ... }
    fn add_sockets(
        &self,
        opts: BroadcastOptions,
        rooms: impl RoomParam,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send { ... }
    fn del_sockets(
        &self,
        opts: BroadcastOptions,
        rooms: impl RoomParam,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send { ... }
    fn disconnect_socket(
        &self,
        opts: BroadcastOptions,
    ) -> impl Future<Output = Result<(), BroadcastError>> + Send { ... }
    fn rooms(
        &self,
        opts: BroadcastOptions,
    ) -> impl Future<Output = Result<Vec<Room>, Self::Error>> + Send { ... }
    fn fetch_sockets(
        &self,
        opts: BroadcastOptions,
    ) -> impl Future<Output = Result<Vec<RemoteSocketData>, Self::Error>> + Send { ... }
}
Expand description

An adapter is responsible for managing the state of the namespace. This adapter can be implemented to share the state between multiple servers.

A CoreLocalAdapter instance will be given when constructing this type, it will allow you to manipulate local sockets (emitting, fetching data, broadcasting).

Required Associated Types§

Source

type Error: StdError + Into<AdapterError> + Send + 'static

An error that can occur when using the adapter.

Source

type State: Send + Sync + 'static

A shared state between all the namespace CoreAdapter. This can be used to share a connection for example.

Source

type AckStream: Stream<Item = AckStreamItem<E::AckError>> + FusedStream + Send + 'static

A stream that emits the acknowledgments of multiple sockets.

Source

type InitRes: Spawnable + Send

A named result type for the initialization of the adapter.

Required Methods§

Source

fn new(state: &Self::State, local: CoreLocalAdapter<E>) -> Self

Creates a new adapter with the given state and local adapter.

The state is used to share a common state between all your adapters. E.G. a connection to a remote system. The local adapter is used to manipulate the local sockets.

Source

fn init( self: Arc<Self>, on_success: impl FnOnce() + Send + 'static, ) -> Self::InitRes

Initializes the adapter. The on_success callback should be called when the adapter ready.

Source

fn broadcast_with_ack( &self, packet: Packet, opts: BroadcastOptions, timeout: Option<Duration>, ) -> impl Future<Output = Result<Self::AckStream, Self::Error>> + Send

Broadcasts the packet to the sockets that match the BroadcastOptions and return a stream of ack responses.

This method does not have default implementation because GAT cannot have default impls. https://github.com/rust-lang/rust/issues/29661

Source

fn get_local(&self) -> &CoreLocalAdapter<E>

Returns the local adapter. Used to enable default behaviors.

Provided Methods§

Source

fn close(&self) -> impl Future<Output = Result<(), Self::Error>> + Send

Closes the adapter.

Source

fn server_count(&self) -> impl Future<Output = Result<u16, Self::Error>> + Send

Returns the number of servers.

Source

fn broadcast( &self, packet: Packet, opts: BroadcastOptions, ) -> impl Future<Output = Result<(), BroadcastError>> + Send

Broadcasts the packet to the sockets that match the BroadcastOptions.

Source

fn add_sockets( &self, opts: BroadcastOptions, rooms: impl RoomParam, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Adds the sockets that match the BroadcastOptions to the rooms.

Source

fn del_sockets( &self, opts: BroadcastOptions, rooms: impl RoomParam, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Removes the sockets that match the BroadcastOptions from the rooms.

Source

fn disconnect_socket( &self, opts: BroadcastOptions, ) -> impl Future<Output = Result<(), BroadcastError>> + Send

Disconnects the sockets that match the BroadcastOptions.

Source

fn rooms( &self, opts: BroadcastOptions, ) -> impl Future<Output = Result<Vec<Room>, Self::Error>> + Send

Fetches rooms that match the BroadcastOptions

Source

fn fetch_sockets( &self, opts: BroadcastOptions, ) -> impl Future<Output = Result<Vec<RemoteSocketData>, Self::Error>> + Send

Fetches remote sockets that match the BroadcastOptions.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§