redis_tower_core/
stream.rs1use std::pin::Pin;
2use std::task::{Context, Poll};
3
4use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
5use tokio::net::TcpStream;
6
7#[cfg(unix)]
8use tokio::net::UnixStream;
9
10pub enum RedisStream {
16 Tcp(TcpStream),
18
19 #[cfg(unix)]
21 Unix(UnixStream),
22
23 #[cfg(feature = "tls-native-tls")]
25 NativeTls(Box<tokio_native_tls::TlsStream<TcpStream>>),
26
27 #[cfg(feature = "tls-rustls")]
29 Rustls(Box<tokio_rustls::client::TlsStream<TcpStream>>),
30}
31
32impl AsyncRead for RedisStream {
33 fn poll_read(
34 self: Pin<&mut Self>,
35 cx: &mut Context<'_>,
36 buf: &mut ReadBuf<'_>,
37 ) -> Poll<std::io::Result<()>> {
38 match self.get_mut() {
39 RedisStream::Tcp(s) => Pin::new(s).poll_read(cx, buf),
40 #[cfg(unix)]
41 RedisStream::Unix(s) => Pin::new(s).poll_read(cx, buf),
42 #[cfg(feature = "tls-native-tls")]
43 RedisStream::NativeTls(s) => Pin::new(s).poll_read(cx, buf),
44 #[cfg(feature = "tls-rustls")]
45 RedisStream::Rustls(s) => Pin::new(s).poll_read(cx, buf),
46 }
47 }
48}
49
50impl AsyncWrite for RedisStream {
51 fn poll_write(
52 self: Pin<&mut Self>,
53 cx: &mut Context<'_>,
54 buf: &[u8],
55 ) -> Poll<std::io::Result<usize>> {
56 match self.get_mut() {
57 RedisStream::Tcp(s) => Pin::new(s).poll_write(cx, buf),
58 #[cfg(unix)]
59 RedisStream::Unix(s) => Pin::new(s).poll_write(cx, buf),
60 #[cfg(feature = "tls-native-tls")]
61 RedisStream::NativeTls(s) => Pin::new(s).poll_write(cx, buf),
62 #[cfg(feature = "tls-rustls")]
63 RedisStream::Rustls(s) => Pin::new(s).poll_write(cx, buf),
64 }
65 }
66
67 fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
68 match self.get_mut() {
69 RedisStream::Tcp(s) => Pin::new(s).poll_flush(cx),
70 #[cfg(unix)]
71 RedisStream::Unix(s) => Pin::new(s).poll_flush(cx),
72 #[cfg(feature = "tls-native-tls")]
73 RedisStream::NativeTls(s) => Pin::new(s).poll_flush(cx),
74 #[cfg(feature = "tls-rustls")]
75 RedisStream::Rustls(s) => Pin::new(s).poll_flush(cx),
76 }
77 }
78
79 fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
80 match self.get_mut() {
81 RedisStream::Tcp(s) => Pin::new(s).poll_shutdown(cx),
82 #[cfg(unix)]
83 RedisStream::Unix(s) => Pin::new(s).poll_shutdown(cx),
84 #[cfg(feature = "tls-native-tls")]
85 RedisStream::NativeTls(s) => Pin::new(s).poll_shutdown(cx),
86 #[cfg(feature = "tls-rustls")]
87 RedisStream::Rustls(s) => Pin::new(s).poll_shutdown(cx),
88 }
89 }
90}