1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-23 22:51:07 +01:00

use impl-more in -tls

This commit is contained in:
Rob Ede 2022-10-17 04:14:09 +01:00
parent c4a0f37d0c
commit 25209f5bd8
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
8 changed files with 10 additions and 57 deletions

View File

@ -25,6 +25,8 @@
/// } /// }
/// } /// }
/// ``` /// ```
///
/// [`forward_ready!`]: crate::forward_ready
#[macro_export] #[macro_export]
macro_rules! always_ready { macro_rules! always_ready {
() => { () => {

View File

@ -48,6 +48,7 @@ actix-service = "2.0.0"
actix-utils = "3.0.0" actix-utils = "3.0.0"
futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] } futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] }
impl-more = "0.1.0"
pin-project-lite = "0.2.7" pin-project-lite = "0.2.7"
tokio-util = "0.7" tokio-util = "0.7"
tracing = { version = "0.1.30", default-features = false, features = ["log"] } tracing = { version = "0.1.30", default-features = false, features = ["log"] }

View File

@ -24,7 +24,6 @@ use futures_core::future::LocalBoxFuture;
use tokio_native_tls::{native_tls::Error, TlsAcceptor}; use tokio_native_tls::{native_tls::Error, TlsAcceptor};
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER}; use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
use crate::impl_more;
pub mod reexports { pub mod reexports {
//! Re-exports from `native-tls` that are useful for acceptors. //! 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`]. /// Wraps a `native-tls` based async TLS stream in order to implement [`ActixStream`].
pub struct TlsStream<IO>(tokio_native_tls::TlsStream<IO>); pub struct TlsStream<IO>(tokio_native_tls::TlsStream<IO>);
impl_more::from! { tokio_native_tls::TlsStream<IO> => TlsStream<IO> } impl_more::impl_from!(<IO> in tokio_native_tls::TlsStream<IO> => TlsStream<IO>);
impl_more::deref! { TlsStream<IO> => 0: tokio_native_tls::TlsStream<IO> } impl_more::impl_deref_and_mut!(<IO> in TlsStream<IO> => tokio_native_tls::TlsStream<IO>);
impl_more::deref_mut! { TlsStream<IO> => 0 }
impl<IO: ActixStream> AsyncRead for TlsStream<IO> { impl<IO: ActixStream> AsyncRead for TlsStream<IO> {
fn poll_read( fn poll_read(

View File

@ -25,7 +25,6 @@ use openssl::ssl::{Error, Ssl, SslAcceptor};
use pin_project_lite::pin_project; use pin_project_lite::pin_project;
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER}; use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
use crate::impl_more;
pub mod reexports { pub mod reexports {
//! Re-exports from `openssl` that are useful for acceptors. //! 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`]. /// Wraps an `openssl` based async TLS stream in order to implement [`ActixStream`].
pub struct TlsStream<IO>(tokio_openssl::SslStream<IO>); pub struct TlsStream<IO>(tokio_openssl::SslStream<IO>);
impl_more::from! { tokio_openssl::SslStream<IO> => TlsStream<IO> } impl_more::impl_from!(<IO> in tokio_openssl::SslStream<IO> => TlsStream<IO>);
impl_more::deref! { TlsStream<IO> => 0: tokio_openssl::SslStream<IO> } impl_more::impl_deref_and_mut!(<IO> in TlsStream<IO> => tokio_openssl::SslStream<IO>);
impl_more::deref_mut! { TlsStream<IO> => 0 }
impl<IO: ActixStream> AsyncRead for TlsStream<IO> { impl<IO: ActixStream> AsyncRead for TlsStream<IO> {
fn poll_read( fn poll_read(

View File

@ -27,7 +27,6 @@ use tokio_rustls::rustls::ServerConfig;
use tokio_rustls::{Accept, TlsAcceptor}; use tokio_rustls::{Accept, TlsAcceptor};
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER}; use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
use crate::impl_more;
pub mod reexports { pub mod reexports {
//! Re-exports from `rustls` that are useful for acceptors. //! 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`]. /// Wraps a `rustls` based async TLS stream in order to implement [`ActixStream`].
pub struct TlsStream<IO>(tokio_rustls::server::TlsStream<IO>); pub struct TlsStream<IO>(tokio_rustls::server::TlsStream<IO>);
impl_more::from! { tokio_rustls::server::TlsStream<IO> => TlsStream<IO> } impl_more::impl_from!(<IO> in tokio_rustls::server::TlsStream<IO> => TlsStream<IO>);
impl_more::deref! { TlsStream<IO> => 0: tokio_rustls::server::TlsStream<IO> } impl_more::impl_deref_and_mut!(<IO> in TlsStream<IO> => tokio_rustls::server::TlsStream<IO>);
impl_more::deref_mut! { TlsStream<IO> => 0 }
impl<IO: ActixStream> AsyncRead for TlsStream<IO> { impl<IO: ActixStream> AsyncRead for TlsStream<IO> {
fn poll_read( fn poll_read(

View File

@ -1,5 +1,4 @@
use super::Host; use super::Host;
use crate::impl_more;
/// Wraps underlying I/O and the connection request that initiated it. /// Wraps underlying I/O and the connection request that initiated it.
#[derive(Debug)] #[derive(Debug)]
@ -8,8 +7,7 @@ pub struct Connection<R, IO> {
pub(crate) io: IO, pub(crate) io: IO,
} }
impl_more::deref! { Connection<R, IO> => io: IO } impl_more::impl_deref_and_mut!(<R, IO> in Connection<R, IO> => io: IO);
impl_more::deref_mut! { Connection<R, IO> => io }
impl<R, IO> Connection<R, IO> { impl<R, IO> Connection<R, IO> {
/// Construct new `Connection` from request and IO parts. /// Construct new `Connection` from request and IO parts.

View File

@ -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};

View File

@ -18,5 +18,3 @@ pub mod accept;
#[cfg(feature = "connect")] #[cfg(feature = "connect")]
#[cfg_attr(docsrs, doc(cfg(feature = "connect")))] #[cfg_attr(docsrs, doc(cfg(feature = "connect")))]
pub mod connect; pub mod connect;
mod impl_more;