diff --git a/actix-tls/CHANGES.md b/actix-tls/CHANGES.md index fde3c460df..fcbbae3944 100644 --- a/actix-tls/CHANGES.md +++ b/actix-tls/CHANGES.md @@ -4,8 +4,10 @@ * Add configurable timeout for accepting TLS connection. [#393] * Added `TlsError::Timeout` variant. [#393] * All TLS acceptor services now use `TlsError` for their error types. [#393] +* Added `TlsError::into_service_error`. [#420] [#393]: https://github.com/actix/actix-net/pull/393 +[#420]: https://github.com/actix/actix-net/pull/420 ## 3.0.0-beta.8 - 2021-11-15 diff --git a/actix-tls/src/accept/mod.rs b/actix-tls/src/accept/mod.rs index ead7927f42..7d0b6dcba0 100644 --- a/actix-tls/src/accept/mod.rs +++ b/actix-tls/src/accept/mod.rs @@ -1,6 +1,9 @@ //! TLS acceptor services. -use std::sync::atomic::{AtomicUsize, Ordering}; +use std::{ + convert::Infallible, + sync::atomic::{AtomicUsize, Ordering}, +}; use actix_utils::counter::Counter; @@ -36,7 +39,29 @@ pub fn max_concurrent_tls_connect(num: usize) { /// TLS error combined with service error. #[derive(Debug)] pub enum TlsError { - Tls(TlsErr), Timeout, + Tls(TlsErr), Service(SvcErr), } + +impl TlsError { + /// Casts the infallible service error type returned from acceptors into caller's type. + pub fn into_service_error(self) -> TlsError { + match self { + Self::Timeout => TlsError::Timeout, + Self::Tls(err) => TlsError::Tls(err), + Self::Service(_) => unreachable!(), + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn tls_service_error_inference() { + let a: TlsError = TlsError::Tls(42); + let _b: TlsError = a.into_service_error(); + } +} diff --git a/actix-tls/src/accept/native_tls.rs b/actix-tls/src/accept/native_tls.rs index a115b5fa24..e61300e62c 100644 --- a/actix-tls/src/accept/native_tls.rs +++ b/actix-tls/src/accept/native_tls.rs @@ -134,7 +134,6 @@ impl ServiceFactory for Acceptor { type Response = TlsStream; type Error = TlsError; type Config = (); - type Service = NativeTlsAcceptorService; type InitError = (); type Future = LocalBoxFuture<'static, Result>; diff --git a/actix-tls/src/accept/rustls.rs b/actix-tls/src/accept/rustls.rs index 04d77ae38d..b0f31365b1 100644 --- a/actix-tls/src/accept/rustls.rs +++ b/actix-tls/src/accept/rustls.rs @@ -138,7 +138,6 @@ impl ServiceFactory for Acceptor { type Response = TlsStream; type Error = TlsError; type Config = (); - type Service = AcceptorService; type InitError = (); type Future = LocalBoxFuture<'static, Result>; diff --git a/actix-tls/src/connect/tls/rustls.rs b/actix-tls/src/connect/tls/rustls.rs index 5abc7673dd..139aadbe98 100755 --- a/actix-tls/src/connect/tls/rustls.rs +++ b/actix-tls/src/connect/tls/rustls.rs @@ -115,7 +115,7 @@ where } pub enum RustlsConnectorServiceFuture { - /// See issue https://github.com/briansmith/webpki/issues/54 + /// See issue InvalidDns, Future { connect: Connect,