sqlx-exasol-impl 0.9.2

Driver implementation for sqlx-exasol. Not meant to be used directly.
Documentation
#[cfg(feature = "tls")]
pub mod tls;

use std::io;

use sqlx_core::net::{Socket, WithSocket};

use crate::{
    connection::websocket::socket::{ExaSocket, WithExaSocket},
    etl::job::WithSocketMaker,
    SqlxResult,
};

/// Implementor of [`WithSocketMaker`] that abstracts away the TLS/non-TLS socket creation.
pub enum WithMaybeTlsSocketMaker {
    NonTls,
    #[cfg(feature = "tls")]
    Tls(tls::WithTlsSocketMaker),
}

impl WithMaybeTlsSocketMaker {
    pub fn new(
        #[allow(unused_variables, reason = "conditionally compiled")] with_tls: bool,
        #[allow(unused_variables, reason = "conditionally compiled")] with_pub_key: bool,
    ) -> SqlxResult<(Self, Option<String>)> {
        #[cfg(feature = "tls")]
        if with_tls {
            let (wsm, public_key) = tls::WithTlsSocketMaker::new(with_pub_key)?;
            return Ok((Self::Tls(wsm), public_key));
        }

        Ok((Self::NonTls, None))
    }
}

impl WithSocketMaker for WithMaybeTlsSocketMaker {
    type WithSocket = WithMaybeTlsSocket;

    fn make_with_socket(&self, with_socket: WithExaSocket) -> Self::WithSocket {
        match self {
            Self::NonTls => WithMaybeTlsSocket::NonTls(with_socket),
            #[cfg(feature = "tls")]
            Self::Tls(w) => WithMaybeTlsSocket::Tls(w.make_with_socket(with_socket)),
        }
    }
}

/// Implementor of [`WithSocket`] that abstracts away the TLS/non-TLS socket creation.
pub enum WithMaybeTlsSocket {
    NonTls(WithExaSocket),
    #[cfg(feature = "tls")]
    Tls(tls::WithTlsSocket),
}

impl WithSocket for WithMaybeTlsSocket {
    type Output = io::Result<ExaSocket>;

    async fn with_socket<S: Socket>(self, socket: S) -> Self::Output {
        match self {
            WithMaybeTlsSocket::NonTls(w) => Ok(w.with_socket(socket).await),
            #[cfg(feature = "tls")]
            WithMaybeTlsSocket::Tls(w) => w.with_socket(socket).await,
        }
    }
}