1use std::{error::Error, future::Future};
2
3use alkahest::{Pack, Schema, Unpacked};
4use scoped_arena::Scope;
5
6#[cfg(feature = "tcp")]
7pub mod tcp;
8
9pub trait ChannelError {
10 type Error: Error + 'static;
11}
12
13pub trait ChannelFuture<'a>: ChannelError {
14 type Send: Future<Output = Result<(), Self::Error>>;
15 type Ready: Future<Output = Result<(), Self::Error>>;
16}
17
18pub trait Channel: ChannelError + for<'a> ChannelFuture<'a> {
20 fn send<'a, S, P>(
23 &'a mut self,
24 packet: P,
25 scope: &'a Scope,
26 ) -> <Self as ChannelFuture<'a>>::Send
27 where
28 S: Schema,
29 P: Pack<S>;
30
31 fn send_reliable<'a, S, P>(
34 &'a mut self,
35 packet: P,
36 scope: &'a Scope,
37 ) -> <Self as ChannelFuture<'a>>::Send
38 where
39 S: Schema,
40 P: Pack<S>;
41
42 fn recv_ready(&mut self) -> <Self as ChannelFuture<'_>>::Ready;
44
45 fn recv<'a, S>(&mut self, scope: &'a Scope) -> Result<Option<Unpacked<'a, S>>, Self::Error>
48 where
49 S: Schema;
50}
51
52pub trait Listener {
53 type Error: Error + 'static;
54 type Channel: Channel;
55
56 fn try_accept(&mut self) -> Result<Option<Self::Channel>, Self::Error>;
57}