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§
Sourcetype Error: StdError + Into<AdapterError> + Send + 'static
type Error: StdError + Into<AdapterError> + Send + 'static
An error that can occur when using the adapter.
Sourcetype State: Send + Sync + 'static
type State: Send + Sync + 'static
A shared state between all the namespace CoreAdapter.
This can be used to share a connection for example.
Sourcetype AckStream: Stream<Item = AckStreamItem<E::AckError>> + FusedStream + Send + 'static
type AckStream: Stream<Item = AckStreamItem<E::AckError>> + FusedStream + Send + 'static
A stream that emits the acknowledgments of multiple sockets.
Required Methods§
Sourcefn new(state: &Self::State, local: CoreLocalAdapter<E>) -> Self
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.
Sourcefn init(
self: Arc<Self>,
on_success: impl FnOnce() + Send + 'static,
) -> Self::InitRes
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.
Sourcefn broadcast_with_ack(
&self,
packet: Packet,
opts: BroadcastOptions,
timeout: Option<Duration>,
) -> impl Future<Output = Result<Self::AckStream, Self::Error>> + Send
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
Sourcefn get_local(&self) -> &CoreLocalAdapter<E>
fn get_local(&self) -> &CoreLocalAdapter<E>
Returns the local adapter. Used to enable default behaviors.
Provided Methods§
Sourcefn server_count(&self) -> impl Future<Output = Result<u16, Self::Error>> + Send
fn server_count(&self) -> impl Future<Output = Result<u16, Self::Error>> + Send
Returns the number of servers.
Sourcefn broadcast(
&self,
packet: Packet,
opts: BroadcastOptions,
) -> impl Future<Output = Result<(), BroadcastError>> + Send
fn broadcast( &self, packet: Packet, opts: BroadcastOptions, ) -> impl Future<Output = Result<(), BroadcastError>> + Send
Broadcasts the packet to the sockets that match the BroadcastOptions.
Sourcefn add_sockets(
&self,
opts: BroadcastOptions,
rooms: impl RoomParam,
) -> impl Future<Output = Result<(), Self::Error>> + Send
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.
Sourcefn del_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
Removes the sockets that match the BroadcastOptions from the rooms.
Sourcefn disconnect_socket(
&self,
opts: BroadcastOptions,
) -> impl Future<Output = Result<(), BroadcastError>> + Send
fn disconnect_socket( &self, opts: BroadcastOptions, ) -> impl Future<Output = Result<(), BroadcastError>> + Send
Disconnects the sockets that match the BroadcastOptions.
Sourcefn rooms(
&self,
opts: BroadcastOptions,
) -> impl Future<Output = Result<Vec<Room>, Self::Error>> + Send
fn rooms( &self, opts: BroadcastOptions, ) -> impl Future<Output = Result<Vec<Room>, Self::Error>> + Send
Fetches rooms that match the BroadcastOptions
Sourcefn fetch_sockets(
&self,
opts: BroadcastOptions,
) -> impl Future<Output = Result<Vec<RemoteSocketData>, Self::Error>> + Send
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", so this trait is not object safe.