tls_api_stub/
stream.rs

1#![allow(dead_code)]
2
3use crate::ImplInfo;
4use std::marker;
5use std::pin::Pin;
6use tls_api::spi::TlsStreamWithUpcastDyn;
7use tls_api::spi_async_socket_impl_delegate;
8use tls_api::AsyncSocket;
9use tls_api::TlsStreamDyn;
10use tls_api::TlsStreamWithSocketDyn;
11use void::Void;
12
13/// Non-instantiatable stream.
14#[derive(Debug)]
15pub struct TlsStream<S: AsyncSocket>(Void, marker::PhantomData<S>);
16
17impl<S: AsyncSocket> TlsStream<S> {
18    fn deref_pin_mut_for_impl_socket(self: Pin<&mut Self>) -> Pin<&mut dyn AsyncSocket> {
19        void::unreachable(self.get_mut().0)
20    }
21
22    fn deref_for_impl_socket(&self) -> Pin<&mut dyn AsyncSocket> {
23        void::unreachable(self.0)
24    }
25}
26
27impl<S: AsyncSocket> TlsStreamDyn for TlsStream<S> {
28    fn get_alpn_protocol(&self) -> anyhow::Result<Option<Vec<u8>>> {
29        void::unreachable(self.0)
30    }
31
32    fn impl_info(&self) -> ImplInfo {
33        void::unreachable(self.0)
34    }
35
36    fn get_socket_dyn_mut(&mut self) -> &mut dyn AsyncSocket {
37        void::unreachable(self.0)
38    }
39
40    fn get_socket_dyn_ref(&self) -> &dyn AsyncSocket {
41        void::unreachable(self.0)
42    }
43}
44
45impl<S: AsyncSocket> TlsStreamWithSocketDyn<S> for TlsStream<S> {
46    fn get_socket_mut(&mut self) -> &mut S {
47        void::unreachable(self.0)
48    }
49
50    fn get_socket_ref(&self) -> &S {
51        void::unreachable(self.0)
52    }
53}
54
55impl<S: AsyncSocket> TlsStreamWithUpcastDyn<S> for TlsStream<S> {
56    fn upcast_box(self: Box<Self>) -> Box<dyn TlsStreamDyn> {
57        self
58    }
59}
60
61spi_async_socket_impl_delegate!(TlsStream<S>);