xwt_core/utils/dummy.rs
1//! Dummy implementations.
2
3use crate::{
4 endpoint,
5 session::{
6 self,
7 stream::{PairSpec, SendSpec},
8 },
9};
10
11use super::maybe;
12
13/// A dummy [`Connecting`] type, that wraps a session and implements
14/// [`endpoint::connect::Connecting`] trait.
15///
16/// Useful when implementing a driver that does not have a meaningful way
17/// to encode the intermediate "connecting session" state, and provides
18/// a fully connected session right away.
19/// Those drivers can use this dummy type instead of implementing their own.
20#[derive(Debug)]
21pub struct Connecting<T>(pub T);
22
23impl<T> endpoint::connect::Connecting for Connecting<T>
24where
25 T: maybe::Send,
26{
27 type Session = T;
28 type Error = core::convert::Infallible;
29
30 async fn wait_connect(self) -> Result<Self::Session, Self::Error> {
31 Ok(self.0)
32 }
33}
34
35/// A dummy [`OpeningUniStream`] type, that wraps a send stream and implements
36/// [`session::stream::OpeningUni`] trait.
37///
38/// Useful when implementing a driver that does not have a meaningful way
39/// to encode the intermediate "opening unidirectional stream" state, and
40/// provides a fully opened stream right away.
41/// Those drivers can use this dummy type instead of implementing their own.
42#[derive(Debug)]
43pub struct OpeningUniStream<T: SendSpec>(pub T::SendStream);
44
45impl<T> session::stream::OpeningUni for OpeningUniStream<T>
46where
47 T: SendSpec,
48{
49 type Streams = T;
50 type Error = core::convert::Infallible;
51
52 async fn wait_uni(self) -> Result<<T as SendSpec>::SendStream, Self::Error> {
53 Ok(self.0)
54 }
55}
56
57/// A dummy [`OpeningBiStream`] type, that wraps a pair of streams and
58/// implements [`session::stream::OpeningBi`] trait.
59///
60/// Useful when implementing a driver that does not have a meaningful way
61/// to encode the intermediate "opening bidirectional stream" state, and
62/// provides a pair of fully opened streams right away.
63/// Those drivers can use this dummy type instead of implementing their own.
64#[derive(Debug)]
65pub struct OpeningBiStream<T: PairSpec>(pub (T::SendStream, T::RecvStream));
66
67impl<T> session::stream::OpeningBi for OpeningBiStream<T>
68where
69 T: PairSpec,
70{
71 type Streams = T;
72 type Error = core::convert::Infallible;
73
74 async fn wait_bi(self) -> Result<session::stream::TupleFor<T>, Self::Error> {
75 Ok(self.0)
76 }
77}