tls_api/
stream.rs

1use crate::assert_kinds::assert_socket;
2use crate::assert_send;
3use crate::socket::AsyncSocket;
4use crate::spi_async_socket_impl_delegate;
5use crate::ImplInfo;
6use crate::TlsStreamDyn;
7use crate::TlsStreamWithSocket;
8use std::pin::Pin;
9
10/// Similar to [`TlsStreamWithSocket`], but without a socket type parameter.
11#[derive(Debug)]
12pub struct TlsStream(Box<dyn TlsStreamDyn>);
13
14fn _assert_kinds() {
15    assert_send::<TlsStream>();
16    assert_socket::<TlsStream>();
17}
18
19impl TlsStream {
20    /// Wrap.
21    pub fn new<S: AsyncSocket>(stream: TlsStreamWithSocket<S>) -> TlsStream {
22        TlsStream(stream.0.upcast_box())
23    }
24
25    fn deref_pin_mut_for_impl_socket(self: Pin<&mut Self>) -> Pin<&mut dyn AsyncSocket> {
26        Pin::new(&mut self.get_mut().0)
27    }
28
29    #[allow(dead_code)]
30    fn deref_for_impl_socket(&self) -> &dyn AsyncSocket {
31        &self.0
32    }
33}
34
35impl TlsStreamDyn for TlsStream {
36    fn get_alpn_protocol(&self) -> anyhow::Result<Option<Vec<u8>>> {
37        self.0.get_alpn_protocol()
38    }
39
40    fn impl_info(&self) -> ImplInfo {
41        self.0.impl_info()
42    }
43
44    fn get_socket_dyn_mut(&mut self) -> &mut dyn AsyncSocket {
45        self.0.get_socket_dyn_mut()
46    }
47
48    fn get_socket_dyn_ref(&self) -> &dyn AsyncSocket {
49        self.0.get_socket_dyn_ref()
50    }
51}
52
53spi_async_socket_impl_delegate!(TlsStream);