use std::sync::Arc;
use tokio_postgres::tls::MakeTlsConnect;
use tokio_postgres_rustls::MakeRustlsConnect;
pub struct PgTls(MakeRustlsConnect);
impl PgTls {
pub fn new(cfg: Arc<rustls::ClientConfig>) -> Self {
let owned = Arc::try_unwrap(cfg).unwrap_or_else(|arc| (*arc).clone());
Self(MakeRustlsConnect::new(owned))
}
}
impl<S> MakeTlsConnect<S> for PgTls
where
S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin + Send + 'static,
{
type Stream = <MakeRustlsConnect as MakeTlsConnect<S>>::Stream;
type TlsConnect = <MakeRustlsConnect as MakeTlsConnect<S>>::TlsConnect;
type Error = <MakeRustlsConnect as MakeTlsConnect<S>>::Error;
fn make_tls_connect(&mut self, domain: &str) -> Result<Self::TlsConnect, Self::Error> {
<MakeRustlsConnect as MakeTlsConnect<S>>::make_tls_connect(&mut self.0, domain)
}
}