Skip to main content

volans_stream/
lib.rs

1pub mod client;
2pub mod server;
3
4use std::convert::Infallible;
5
6use futures::future::{Ready, ready};
7use volans_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
8use volans_swarm::{StreamProtocol, Substream};
9
10pub struct Upgrade {
11    pub(crate) supported_protocols: Vec<StreamProtocol>,
12}
13
14impl UpgradeInfo for Upgrade {
15    type Info = StreamProtocol;
16
17    type InfoIter = std::vec::IntoIter<StreamProtocol>;
18
19    fn protocol_info(&self) -> Self::InfoIter {
20        self.supported_protocols.clone().into_iter()
21    }
22}
23
24impl InboundUpgrade<Substream> for Upgrade {
25    type Output = (Substream, StreamProtocol);
26
27    type Error = Infallible;
28
29    type Future = Ready<Result<Self::Output, Self::Error>>;
30
31    fn upgrade_inbound(self, socket: Substream, info: Self::Info) -> Self::Future {
32        ready(Ok((socket, info)))
33    }
34}
35
36impl OutboundUpgrade<Substream> for Upgrade {
37    type Output = (Substream, StreamProtocol);
38
39    type Error = Infallible;
40
41    type Future = Ready<Result<Self::Output, Self::Error>>;
42
43    fn upgrade_outbound(self, socket: Substream, info: Self::Info) -> Self::Future {
44        ready(Ok((socket, info)))
45    }
46}