fire_http_api/stream/
stream.rs

1//! The names are in the perspective of the client
2
3use super::message::MessageKind;
4use crate::error::ApiError;
5
6use serde::{de::DeserializeOwned, Serialize};
7
8/// ## Note
9/// The names are in the perspective of a client so a StreamKind of Sender will
10/// mean the client sends data and the server receives it.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
12pub enum StreamKind {
13	Sender,
14	Receiver,
15}
16
17impl StreamKind {
18	pub fn into_kind_message(self) -> MessageKind {
19		match self {
20			Self::Sender => MessageKind::SenderMessage,
21			Self::Receiver => MessageKind::ReceiverMessage,
22		}
23	}
24}
25
26impl From<MessageKind> for StreamKind {
27	fn from(m: MessageKind) -> Self {
28		match m {
29			MessageKind::SenderRequest
30			| MessageKind::SenderMessage
31			| MessageKind::SenderClose => Self::Sender,
32			MessageKind::ReceiverRequest
33			| MessageKind::ReceiverMessage
34			| MessageKind::ReceiverClose => Self::Receiver,
35		}
36	}
37}
38
39/// The struct of the stream itself is like a request to start the stream
40pub trait Stream: Serialize + DeserializeOwned {
41	type Message: Serialize + DeserializeOwned;
42	/// After an error occured the stream get's closed
43	type Error: ApiError;
44
45	const KIND: StreamKind;
46	const ACTION: &'static str;
47}