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#[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 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 fn deref_for_impl_socket(&self) -> &dyn AsyncSocket {
30 &self.0
31 }
32}
33
34impl TlsStreamDyn for TlsStream {
35 fn get_alpn_protocol(&self) -> anyhow::Result<Option<Vec<u8>>> {
36 self.0.get_alpn_protocol()
37 }
38
39 fn impl_info(&self) -> ImplInfo {
40 self.0.impl_info()
41 }
42
43 fn get_socket_dyn_mut(&mut self) -> &mut dyn AsyncSocket {
44 self.0.get_socket_dyn_mut()
45 }
46
47 fn get_socket_dyn_ref(&self) -> &dyn AsyncSocket {
48 self.0.get_socket_dyn_ref()
49 }
50}
51
52spi_async_socket_impl_delegate!(TlsStream);