mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-27 16:52:58 +01:00
use impl-more in -tls
This commit is contained in:
parent
c4a0f37d0c
commit
25209f5bd8
@ -25,6 +25,8 @@
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// [`forward_ready!`]: crate::forward_ready
|
||||
#[macro_export]
|
||||
macro_rules! always_ready {
|
||||
() => {
|
||||
|
@ -48,6 +48,7 @@ actix-service = "2.0.0"
|
||||
actix-utils = "3.0.0"
|
||||
|
||||
futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] }
|
||||
impl-more = "0.1.0"
|
||||
pin-project-lite = "0.2.7"
|
||||
tokio-util = "0.7"
|
||||
tracing = { version = "0.1.30", default-features = false, features = ["log"] }
|
||||
|
@ -24,7 +24,6 @@ use futures_core::future::LocalBoxFuture;
|
||||
use tokio_native_tls::{native_tls::Error, TlsAcceptor};
|
||||
|
||||
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
|
||||
use crate::impl_more;
|
||||
|
||||
pub mod reexports {
|
||||
//! Re-exports from `native-tls` that are useful for acceptors.
|
||||
@ -35,9 +34,8 @@ pub mod reexports {
|
||||
/// Wraps a `native-tls` based async TLS stream in order to implement [`ActixStream`].
|
||||
pub struct TlsStream<IO>(tokio_native_tls::TlsStream<IO>);
|
||||
|
||||
impl_more::from! { tokio_native_tls::TlsStream<IO> => TlsStream<IO> }
|
||||
impl_more::deref! { TlsStream<IO> => 0: tokio_native_tls::TlsStream<IO> }
|
||||
impl_more::deref_mut! { TlsStream<IO> => 0 }
|
||||
impl_more::impl_from!(<IO> in tokio_native_tls::TlsStream<IO> => TlsStream<IO>);
|
||||
impl_more::impl_deref_and_mut!(<IO> in TlsStream<IO> => tokio_native_tls::TlsStream<IO>);
|
||||
|
||||
impl<IO: ActixStream> AsyncRead for TlsStream<IO> {
|
||||
fn poll_read(
|
||||
|
@ -25,7 +25,6 @@ use openssl::ssl::{Error, Ssl, SslAcceptor};
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
|
||||
use crate::impl_more;
|
||||
|
||||
pub mod reexports {
|
||||
//! Re-exports from `openssl` that are useful for acceptors.
|
||||
@ -38,9 +37,8 @@ pub mod reexports {
|
||||
/// Wraps an `openssl` based async TLS stream in order to implement [`ActixStream`].
|
||||
pub struct TlsStream<IO>(tokio_openssl::SslStream<IO>);
|
||||
|
||||
impl_more::from! { tokio_openssl::SslStream<IO> => TlsStream<IO> }
|
||||
impl_more::deref! { TlsStream<IO> => 0: tokio_openssl::SslStream<IO> }
|
||||
impl_more::deref_mut! { TlsStream<IO> => 0 }
|
||||
impl_more::impl_from!(<IO> in tokio_openssl::SslStream<IO> => TlsStream<IO>);
|
||||
impl_more::impl_deref_and_mut!(<IO> in TlsStream<IO> => tokio_openssl::SslStream<IO>);
|
||||
|
||||
impl<IO: ActixStream> AsyncRead for TlsStream<IO> {
|
||||
fn poll_read(
|
||||
|
@ -27,7 +27,6 @@ use tokio_rustls::rustls::ServerConfig;
|
||||
use tokio_rustls::{Accept, TlsAcceptor};
|
||||
|
||||
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
|
||||
use crate::impl_more;
|
||||
|
||||
pub mod reexports {
|
||||
//! Re-exports from `rustls` that are useful for acceptors.
|
||||
@ -38,9 +37,8 @@ pub mod reexports {
|
||||
/// Wraps a `rustls` based async TLS stream in order to implement [`ActixStream`].
|
||||
pub struct TlsStream<IO>(tokio_rustls::server::TlsStream<IO>);
|
||||
|
||||
impl_more::from! { tokio_rustls::server::TlsStream<IO> => TlsStream<IO> }
|
||||
impl_more::deref! { TlsStream<IO> => 0: tokio_rustls::server::TlsStream<IO> }
|
||||
impl_more::deref_mut! { TlsStream<IO> => 0 }
|
||||
impl_more::impl_from!(<IO> in tokio_rustls::server::TlsStream<IO> => TlsStream<IO>);
|
||||
impl_more::impl_deref_and_mut!(<IO> in TlsStream<IO> => tokio_rustls::server::TlsStream<IO>);
|
||||
|
||||
impl<IO: ActixStream> AsyncRead for TlsStream<IO> {
|
||||
fn poll_read(
|
||||
|
@ -1,5 +1,4 @@
|
||||
use super::Host;
|
||||
use crate::impl_more;
|
||||
|
||||
/// Wraps underlying I/O and the connection request that initiated it.
|
||||
#[derive(Debug)]
|
||||
@ -8,8 +7,7 @@ pub struct Connection<R, IO> {
|
||||
pub(crate) io: IO,
|
||||
}
|
||||
|
||||
impl_more::deref! { Connection<R, IO> => io: IO }
|
||||
impl_more::deref_mut! { Connection<R, IO> => io }
|
||||
impl_more::impl_deref_and_mut!(<R, IO> in Connection<R, IO> => io: IO);
|
||||
|
||||
impl<R, IO> Connection<R, IO> {
|
||||
/// Construct new `Connection` from request and IO parts.
|
||||
|
@ -1,40 +0,0 @@
|
||||
/// A helper to implement `Deref` for a type.
|
||||
#[macro_export]
|
||||
macro_rules! deref {
|
||||
($ty:ident $(<$($generic:ident),*>)? => $field:tt: $target:ty) => {
|
||||
impl $(<$($generic),*>)? ::core::ops::Deref for $ty $(<$($generic),*>)? {
|
||||
type Target = $target;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.$field
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// A helper to implement `DerefMut` for a type.
|
||||
#[macro_export]
|
||||
macro_rules! deref_mut {
|
||||
($ty:ident $(<$($generic:ident),*>)? => $field:tt) => {
|
||||
impl $(<$($generic),*>)? ::core::ops::DerefMut for $ty $(<$($generic),*>)? {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.$field
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// A helper to implement `From` for a unit struct.
|
||||
#[macro_export]
|
||||
macro_rules! from {
|
||||
($from:ty => $ty:ident $(<$($generic:ident),*>)?) => {
|
||||
impl $(<$($generic),*>)? ::core::convert::From<$from> for $ty $(<$($generic),*>)? {
|
||||
fn from(from: $from) -> Self {
|
||||
Self(from)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[allow(unused_imports)]
|
||||
pub(crate) use crate::{deref, deref_mut, from};
|
@ -18,5 +18,3 @@ pub mod accept;
|
||||
#[cfg(feature = "connect")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "connect")))]
|
||||
pub mod connect;
|
||||
|
||||
mod impl_more;
|
||||
|
Loading…
Reference in New Issue
Block a user