1use crate::error::ApiError;
2use crate::message::Action;
3#[cfg(feature = "connection")]
4use crate::{
5 error::Error,
6 message::Message,
7 requestor::Requestor,
8 server::{Data, Session},
9};
10
11#[cfg(feature = "connection")]
12use lafere::standalone_util::PinnedFuture;
13
14pub trait Request {
16 type Action: Action;
17 type Response;
18 type Error: ApiError;
19
20 const ACTION: Self::Action;
21}
22
23#[cfg(feature = "connection")]
24pub trait RequestHandler<B> {
25 type Action: Action;
26
27 fn action() -> Self::Action
28 where
29 Self: Sized;
30
31 fn validate_data(&self, data: &Data);
33
34 fn handle<'a>(
39 &'a self,
40 msg: Message<Self::Action, B>,
41 data: &'a Data,
42 session: &'a Session,
43 ) -> PinnedFuture<'a, Result<Message<Self::Action, B>, Error>>;
44}
45
46#[cfg(feature = "connection")]
47pub trait EnableServerRequestsHandler<B> {
48 type Action: Action;
49
50 fn validate_data(&self, data: &Data);
52
53 fn handle<'a>(
58 &'a self,
59 sender: Requestor<Self::Action, B>,
60 data: &'a Data,
61 session: &'a Session,
62 ) -> PinnedFuture<'a, Result<(), Error>>;
63}