ygopro_handler/room.rs
1//! The room abstraction: turns a client-to-server stream into a server-to-client stream.
2//!
3//! A [`RoomProvider`] is a duel that accepts a client-to-server message stream and returns
4//! the matching server-to-client message stream, plus a future that signals when the room
5//! finishes.
6
7use std::future::Future;
8
9use futures::Stream;
10
11/// Abstract of a duel.
12///
13/// Implementing this trait means it can accept a stream of `ClientToServerMessage` and
14/// return a stream of `ServerToClientMessage`.
15///
16/// Usually `ClientToServerMessage` is a derived type of [`ctos::Message`](ygopro_data::message::ctos::Message), and
17/// `ServerToClientMessage` is a derived type of [`stoc::Message`](ygopro_data::message::stoc::Message).
18pub trait RoomProvider<ClientToServerMessage, ServerToClientMessage> {
19 /// The stream of messages sent back to the client.
20 type ServerToClientStream: Stream<Item = ServerToClientMessage> + Unpin + Send + 'static;
21 /// A future that resolves when the room finishes.
22 type FinishFuture: Future<Output = ()> + Unpin + Send + 'static;
23
24 /// Add a client-to-server stream and return the corresponding server-to-client stream.
25 fn add(&mut self, client_to_server_stream: impl Stream<Item = ClientToServerMessage> + Unpin + Send + 'static) -> Self::ServerToClientStream;
26 /// Get a future that resolves when the room finishes.
27 fn get_finish_signal(&mut self) -> Self::FinishFuture;
28}