mysql_async/error/tls/
native_tls_error.rs

1#![cfg(feature = "native-tls-tls")]
2
3use std::fmt::Display;
4
5#[derive(Debug)]
6pub enum TlsError {
7    TlsError(native_tls::Error),
8    TlsHandshakeError(native_tls::HandshakeError<std::net::TcpStream>),
9}
10
11impl From<TlsError> for crate::Error {
12    fn from(err: TlsError) -> crate::Error {
13        crate::Error::Io(crate::error::IoError::Tls(err))
14    }
15}
16
17impl From<native_tls::Error> for crate::Error {
18    fn from(err: native_tls::Error) -> crate::Error {
19        crate::Error::Io(crate::error::IoError::Tls(TlsError::TlsError(err)))
20    }
21}
22
23impl From<native_tls::HandshakeError<std::net::TcpStream>> for crate::Error {
24    fn from(err: native_tls::HandshakeError<std::net::TcpStream>) -> crate::Error {
25        crate::Error::Io(crate::error::IoError::Tls(TlsError::TlsHandshakeError(err)))
26    }
27}
28
29impl std::error::Error for TlsError {
30    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
31        match self {
32            TlsError::TlsError(e) => Some(e),
33            TlsError::TlsHandshakeError(e) => Some(e),
34        }
35    }
36}
37
38impl Display for TlsError {
39    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40        match self {
41            TlsError::TlsError(e) => e.fmt(f),
42            TlsError::TlsHandshakeError(e) => e.fmt(f),
43        }
44    }
45}