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