fire_stream_api/
request.rs

1use crate::message::Action;
2use crate::error::ApiError;
3#[cfg(feature = "connection")]
4use crate::{
5	message::Message,
6	error::Error,
7	server::{Data, Session}
8};
9
10#[cfg(feature = "connection")]
11use stream::standalone_util::PinnedFuture;
12
13
14/// Basic request definition.
15pub 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 Self: Sized;
29
30	/// if the data is not available just panic
31	fn validate_data(&self, data: &Data);
32
33	/// handles a message with Self::ACTION as action.
34	/// 
35	/// if None is returned the request is abandoned and
36	/// the requestor receives a RequestDropped error
37	fn handle<'a>(
38		&'a self,
39		msg: Message<Self::Action, B>,
40		data: &'a Data,
41		session: &'a Session
42	) -> PinnedFuture<'a, Result<Message<Self::Action, B>, Error>>;
43}