1#[macro_use]
5mod connection;
6#[macro_use]
7mod splittable;
8#[macro_use]
9mod receive;
10#[macro_use]
11mod send;
12#[macro_use]
13mod bidirectional;
14
15mod local;
16mod peer;
17
18pub use s2n_quic_core::stream::{StreamError as Error, StreamType as Type};
19
20pub use bidirectional::*;
21pub use local::*;
22pub use peer::*;
23pub use receive::*;
24pub use send::*;
25pub use splittable::*;
26
27pub type Result<T, E = Error> = core::result::Result<T, E>;
28
29#[derive(Debug)]
31pub enum Stream {
32 Bidirectional(BidirectionalStream),
33 Receive(ReceiveStream),
34 Send(SendStream),
35}
36
37impl Stream {
38 #[inline]
60 pub fn id(&self) -> u64 {
61 match self {
62 Self::Bidirectional(stream) => stream.id(),
63 Self::Receive(stream) => stream.id(),
64 Self::Send(stream) => stream.id(),
65 }
66 }
67
68 impl_connection_api!(|stream| match stream {
69 Stream::Bidirectional(stream) => stream.connection(),
70 Stream::Receive(stream) => stream.connection(),
71 Stream::Send(stream) => stream.connection(),
72 });
73
74 impl_receive_stream_api!(|stream, dispatch| match stream {
75 Stream::Bidirectional(stream) => dispatch!(stream),
76 Stream::Receive(stream) => dispatch!(stream),
77 Stream::Send(_stream) => dispatch!(),
78 });
79
80 impl_send_stream_api!(|stream, dispatch| match stream {
81 Stream::Bidirectional(stream) => dispatch!(stream),
82 Stream::Receive(_stream) => dispatch!(),
83 Stream::Send(stream) => dispatch!(stream),
84 });
85
86 impl_splittable_stream_api!();
87}
88
89impl_receive_stream_trait!(Stream, |stream, dispatch| match stream {
90 Stream::Bidirectional(stream) => dispatch!(stream),
91 Stream::Receive(stream) => dispatch!(stream),
92 Stream::Send(_stream) => dispatch!(),
93});
94impl_send_stream_trait!(Stream, |stream, dispatch| match stream {
95 Stream::Bidirectional(stream) => dispatch!(stream),
96 Stream::Receive(_stream) => dispatch!(),
97 Stream::Send(stream) => dispatch!(stream),
98});
99impl_splittable_stream_trait!(Stream, |stream| match stream {
100 Stream::Bidirectional(stream) => SplittableStream::split(stream),
101 Stream::Receive(stream) => SplittableStream::split(stream),
102 Stream::Send(stream) => SplittableStream::split(stream),
103});
104
105impl From<ReceiveStream> for Stream {
106 #[inline]
107 fn from(stream: ReceiveStream) -> Self {
108 Self::Receive(stream)
109 }
110}
111
112impl From<SendStream> for Stream {
113 #[inline]
114 fn from(stream: SendStream) -> Self {
115 Self::Send(stream)
116 }
117}
118
119impl From<BidirectionalStream> for Stream {
120 #[inline]
121 fn from(stream: BidirectionalStream) -> Self {
122 Self::Bidirectional(stream)
123 }
124}