mirror of https://github.com/fafhrd91/actix-net
				
				
				
			standardize code format
This commit is contained in:
		
							parent
							
								
									56028e2f37
								
							
						
					
					
						commit
						4d3c11f4c9
					
				| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
group_imports = "StdExternalCrate"
 | 
			
		||||
imports_granularity = "Crate"
 | 
			
		||||
use_field_init_shorthand = true
 | 
			
		||||
| 
						 | 
				
			
			@ -234,10 +234,7 @@ impl<T, U> Framed<T, U> {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /// Flush write buffer to underlying I/O stream.
 | 
			
		||||
    pub fn flush<I>(
 | 
			
		||||
        mut self: Pin<&mut Self>,
 | 
			
		||||
        cx: &mut Context<'_>,
 | 
			
		||||
    ) -> Poll<Result<(), U::Error>>
 | 
			
		||||
    pub fn flush<I>(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), U::Error>>
 | 
			
		||||
    where
 | 
			
		||||
        T: AsyncWrite,
 | 
			
		||||
        U: Encoder<I>,
 | 
			
		||||
| 
						 | 
				
			
			@ -270,10 +267,7 @@ impl<T, U> Framed<T, U> {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /// Flush write buffer and shutdown underlying I/O stream.
 | 
			
		||||
    pub fn close<I>(
 | 
			
		||||
        mut self: Pin<&mut Self>,
 | 
			
		||||
        cx: &mut Context<'_>,
 | 
			
		||||
    ) -> Poll<Result<(), U::Error>>
 | 
			
		||||
    pub fn close<I>(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), U::Error>>
 | 
			
		||||
    where
 | 
			
		||||
        T: AsyncWrite,
 | 
			
		||||
        U: Encoder<I>,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,14 +11,18 @@
 | 
			
		|||
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
 | 
			
		||||
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
 | 
			
		||||
 | 
			
		||||
pub use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
 | 
			
		||||
pub use tokio_util::{
 | 
			
		||||
    codec::{Decoder, Encoder},
 | 
			
		||||
    io::poll_read_buf,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
mod bcodec;
 | 
			
		||||
mod framed;
 | 
			
		||||
mod lines;
 | 
			
		||||
 | 
			
		||||
pub use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
 | 
			
		||||
pub use tokio_util::codec::{Decoder, Encoder};
 | 
			
		||||
pub use tokio_util::io::poll_read_buf;
 | 
			
		||||
 | 
			
		||||
pub use self::bcodec::BytesCodec;
 | 
			
		||||
pub use self::framed::{Framed, FramedParts};
 | 
			
		||||
pub use self::lines::LinesCodec;
 | 
			
		||||
pub use self::{
 | 
			
		||||
    bcodec::BytesCodec,
 | 
			
		||||
    framed::{Framed, FramedParts},
 | 
			
		||||
    lines::LinesCodec,
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -81,10 +81,7 @@ impl AsyncWrite for Bilateral {
 | 
			
		|||
            other => Ready(other),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    fn poll_shutdown(
 | 
			
		||||
        self: Pin<&mut Self>,
 | 
			
		||||
        _cx: &mut Context<'_>,
 | 
			
		||||
    ) -> Poll<Result<(), io::Error>> {
 | 
			
		||||
    fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
 | 
			
		||||
        unimplemented!()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,8 +20,7 @@ fn main() {
 | 
			
		|||
        let make_service =
 | 
			
		||||
            make_service_fn(|_conn| async { Ok::<_, Infallible>(service_fn(handle)) });
 | 
			
		||||
 | 
			
		||||
        let server =
 | 
			
		||||
            Server::bind(&SocketAddr::from(([127, 0, 0, 1], 3000))).serve(make_service);
 | 
			
		||||
        let server = Server::bind(&SocketAddr::from(([127, 0, 0, 1], 3000))).serve(make_service);
 | 
			
		||||
 | 
			
		||||
        if let Err(err) = server.await {
 | 
			
		||||
            eprintln!("server error: {}", err);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -99,8 +99,7 @@ impl Arbiter {
 | 
			
		|||
    #[allow(clippy::new_without_default)]
 | 
			
		||||
    pub fn new() -> Arbiter {
 | 
			
		||||
        Self::with_tokio_rt(|| {
 | 
			
		||||
            crate::runtime::default_tokio_runtime()
 | 
			
		||||
                .expect("Cannot create new Arbiter's Runtime.")
 | 
			
		||||
            crate::runtime::default_tokio_runtime().expect("Cannot create new Arbiter's Runtime.")
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -149,9 +148,7 @@ impl Arbiter {
 | 
			
		|||
                        .send(SystemCommand::DeregisterArbiter(arb_id));
 | 
			
		||||
                }
 | 
			
		||||
            })
 | 
			
		||||
            .unwrap_or_else(|err| {
 | 
			
		||||
                panic!("Cannot spawn Arbiter's thread: {:?}. {:?}", &name, err)
 | 
			
		||||
            });
 | 
			
		||||
            .unwrap_or_else(|err| panic!("Cannot spawn Arbiter's thread: {name:?}: {err:?}"));
 | 
			
		||||
 | 
			
		||||
        ready_rx.recv().unwrap();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -201,9 +198,7 @@ impl Arbiter {
 | 
			
		|||
                        .send(SystemCommand::DeregisterArbiter(arb_id));
 | 
			
		||||
                }
 | 
			
		||||
            })
 | 
			
		||||
            .unwrap_or_else(|err| {
 | 
			
		||||
                panic!("Cannot spawn Arbiter's thread: {:?}. {:?}", &name, err)
 | 
			
		||||
            });
 | 
			
		||||
            .unwrap_or_else(|err| panic!("Cannot spawn Arbiter's thread: {name:?}: {err:?}"));
 | 
			
		||||
 | 
			
		||||
        ready_rx.recv().unwrap();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -65,9 +65,11 @@ mod system;
 | 
			
		|||
pub use tokio::pin;
 | 
			
		||||
use tokio::task::JoinHandle;
 | 
			
		||||
 | 
			
		||||
pub use self::arbiter::{Arbiter, ArbiterHandle};
 | 
			
		||||
pub use self::runtime::Runtime;
 | 
			
		||||
pub use self::system::{System, SystemRunner};
 | 
			
		||||
pub use self::{
 | 
			
		||||
    arbiter::{Arbiter, ArbiterHandle},
 | 
			
		||||
    runtime::Runtime,
 | 
			
		||||
    system::{System, SystemRunner},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
pub mod signal {
 | 
			
		||||
    //! Asynchronous signal handling (Tokio re-exports).
 | 
			
		||||
| 
						 | 
				
			
			@ -89,12 +91,13 @@ pub mod net {
 | 
			
		|||
        task::{Context, Poll},
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    pub use tokio::io::Ready;
 | 
			
		||||
    use tokio::io::{AsyncRead, AsyncWrite, Interest};
 | 
			
		||||
    pub use tokio::net::UdpSocket;
 | 
			
		||||
    pub use tokio::net::{TcpListener, TcpSocket, TcpStream};
 | 
			
		||||
    #[cfg(unix)]
 | 
			
		||||
    pub use tokio::net::{UnixDatagram, UnixListener, UnixStream};
 | 
			
		||||
    pub use tokio::{
 | 
			
		||||
        io::Ready,
 | 
			
		||||
        net::{TcpListener, TcpSocket, TcpStream, UdpSocket},
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    /// Extension trait over async read+write types that can also signal readiness.
 | 
			
		||||
    #[doc(hidden)]
 | 
			
		||||
| 
						 | 
				
			
			@ -153,10 +156,9 @@ pub mod net {
 | 
			
		|||
pub mod time {
 | 
			
		||||
    //! Utilities for tracking time (Tokio re-exports).
 | 
			
		||||
 | 
			
		||||
    pub use tokio::time::Instant;
 | 
			
		||||
    pub use tokio::time::{interval, interval_at, Interval};
 | 
			
		||||
    pub use tokio::time::{sleep, sleep_until, Sleep};
 | 
			
		||||
    pub use tokio::time::{timeout, Timeout};
 | 
			
		||||
    pub use tokio::time::{
 | 
			
		||||
        interval, interval_at, sleep, sleep_until, timeout, Instant, Interval, Sleep, Timeout,
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub mod task {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -226,9 +226,7 @@ impl SystemRunner {
 | 
			
		|||
 | 
			
		||||
    /// Runs the event loop until [stopped](System::stop_with_code), returning the exit code.
 | 
			
		||||
    pub fn run_with_code(self) -> io::Result<i32> {
 | 
			
		||||
        unimplemented!(
 | 
			
		||||
            "SystemRunner::run_with_code is not implemented for io-uring feature yet"
 | 
			
		||||
        );
 | 
			
		||||
        unimplemented!("SystemRunner::run_with_code is not implemented for io-uring feature yet");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Runs the provided future, blocking the current thread until the future completes.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,9 +7,7 @@ use tracing::{info, trace};
 | 
			
		|||
use crate::{
 | 
			
		||||
    server::ServerCommand,
 | 
			
		||||
    service::{InternalServiceFactory, ServerServiceFactory, StreamNewService},
 | 
			
		||||
    socket::{
 | 
			
		||||
        create_mio_tcp_listener, MioListener, MioTcpListener, StdTcpListener, ToSocketAddrs,
 | 
			
		||||
    },
 | 
			
		||||
    socket::{create_mio_tcp_listener, MioListener, MioTcpListener, StdTcpListener, ToSocketAddrs},
 | 
			
		||||
    worker::ServerWorkerConfig,
 | 
			
		||||
    Server,
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			@ -246,8 +244,7 @@ impl ServerBuilder {
 | 
			
		|||
        use std::net::{IpAddr, Ipv4Addr};
 | 
			
		||||
        lst.set_nonblocking(true)?;
 | 
			
		||||
        let token = self.next_token();
 | 
			
		||||
        let addr =
 | 
			
		||||
            crate::socket::StdSocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
 | 
			
		||||
        let addr = crate::socket::StdSocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
 | 
			
		||||
        self.factories.push(StreamNewService::create(
 | 
			
		||||
            name.as_ref().to_string(),
 | 
			
		||||
            token,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,13 +18,12 @@ mod test_server;
 | 
			
		|||
mod waker_queue;
 | 
			
		||||
mod worker;
 | 
			
		||||
 | 
			
		||||
pub use self::builder::ServerBuilder;
 | 
			
		||||
pub use self::handle::ServerHandle;
 | 
			
		||||
pub use self::server::Server;
 | 
			
		||||
pub use self::service::ServerServiceFactory;
 | 
			
		||||
#[doc(hidden)]
 | 
			
		||||
pub use self::socket::FromStream;
 | 
			
		||||
pub use self::test_server::TestServer;
 | 
			
		||||
pub use self::{
 | 
			
		||||
    builder::ServerBuilder, handle::ServerHandle, server::Server, service::ServerServiceFactory,
 | 
			
		||||
    test_server::TestServer,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/// Start server building process
 | 
			
		||||
#[doc(hidden)]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,8 +8,7 @@ pub(crate) use mio::net::TcpListener as MioTcpListener;
 | 
			
		|||
use mio::{event::Source, Interest, Registry, Token};
 | 
			
		||||
#[cfg(unix)]
 | 
			
		||||
pub(crate) use {
 | 
			
		||||
    mio::net::UnixListener as MioUnixListener,
 | 
			
		||||
    std::os::unix::net::UnixListener as StdUnixListener,
 | 
			
		||||
    mio::net::UnixListener as MioUnixListener, std::os::unix::net::UnixListener as StdUnixListener,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
pub(crate) enum MioListener {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -625,8 +625,8 @@ impl Future for ServerWorker {
 | 
			
		|||
                let factory_id = restart.factory_id;
 | 
			
		||||
                let token = restart.token;
 | 
			
		||||
 | 
			
		||||
                let (token_new, service) = ready!(restart.fut.as_mut().poll(cx))
 | 
			
		||||
                    .unwrap_or_else(|_| {
 | 
			
		||||
                let (token_new, service) =
 | 
			
		||||
                    ready!(restart.fut.as_mut().poll(cx)).unwrap_or_else(|_| {
 | 
			
		||||
                        panic!(
 | 
			
		||||
                            "Can not restart {:?} service",
 | 
			
		||||
                            this.factories[factory_id].name(token)
 | 
			
		||||
| 
						 | 
				
			
			@ -706,9 +706,7 @@ impl Future for ServerWorker {
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn wrap_worker_services(
 | 
			
		||||
    services: Vec<(usize, usize, BoxedServerService)>,
 | 
			
		||||
) -> Vec<WorkerService> {
 | 
			
		||||
fn wrap_worker_services(services: Vec<(usize, usize, BoxedServerService)>) -> Vec<WorkerService> {
 | 
			
		||||
    services
 | 
			
		||||
        .into_iter()
 | 
			
		||||
        .fold(Vec::new(), |mut services, (idx, token, service)| {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -121,12 +121,7 @@ pub struct AndThenServiceFactory<A, B, Req>
 | 
			
		|||
where
 | 
			
		||||
    A: ServiceFactory<Req>,
 | 
			
		||||
    A::Config: Clone,
 | 
			
		||||
    B: ServiceFactory<
 | 
			
		||||
        A::Response,
 | 
			
		||||
        Config = A::Config,
 | 
			
		||||
        Error = A::Error,
 | 
			
		||||
        InitError = A::InitError,
 | 
			
		||||
    >,
 | 
			
		||||
    B: ServiceFactory<A::Response, Config = A::Config, Error = A::Error, InitError = A::InitError>,
 | 
			
		||||
{
 | 
			
		||||
    inner: Rc<(A, B)>,
 | 
			
		||||
    _phantom: PhantomData<Req>,
 | 
			
		||||
| 
						 | 
				
			
			@ -136,12 +131,7 @@ impl<A, B, Req> AndThenServiceFactory<A, B, Req>
 | 
			
		|||
where
 | 
			
		||||
    A: ServiceFactory<Req>,
 | 
			
		||||
    A::Config: Clone,
 | 
			
		||||
    B: ServiceFactory<
 | 
			
		||||
        A::Response,
 | 
			
		||||
        Config = A::Config,
 | 
			
		||||
        Error = A::Error,
 | 
			
		||||
        InitError = A::InitError,
 | 
			
		||||
    >,
 | 
			
		||||
    B: ServiceFactory<A::Response, Config = A::Config, Error = A::Error, InitError = A::InitError>,
 | 
			
		||||
{
 | 
			
		||||
    /// Create new `AndThenFactory` combinator
 | 
			
		||||
    pub(crate) fn new(a: A, b: B) -> Self {
 | 
			
		||||
| 
						 | 
				
			
			@ -156,12 +146,7 @@ impl<A, B, Req> ServiceFactory<Req> for AndThenServiceFactory<A, B, Req>
 | 
			
		|||
where
 | 
			
		||||
    A: ServiceFactory<Req>,
 | 
			
		||||
    A::Config: Clone,
 | 
			
		||||
    B: ServiceFactory<
 | 
			
		||||
        A::Response,
 | 
			
		||||
        Config = A::Config,
 | 
			
		||||
        Error = A::Error,
 | 
			
		||||
        InitError = A::InitError,
 | 
			
		||||
    >,
 | 
			
		||||
    B: ServiceFactory<A::Response, Config = A::Config, Error = A::Error, InitError = A::InitError>,
 | 
			
		||||
{
 | 
			
		||||
    type Response = B::Response;
 | 
			
		||||
    type Error = A::Error;
 | 
			
		||||
| 
						 | 
				
			
			@ -184,12 +169,7 @@ impl<A, B, Req> Clone for AndThenServiceFactory<A, B, Req>
 | 
			
		|||
where
 | 
			
		||||
    A: ServiceFactory<Req>,
 | 
			
		||||
    A::Config: Clone,
 | 
			
		||||
    B: ServiceFactory<
 | 
			
		||||
        A::Response,
 | 
			
		||||
        Config = A::Config,
 | 
			
		||||
        Error = A::Error,
 | 
			
		||||
        InitError = A::InitError,
 | 
			
		||||
    >,
 | 
			
		||||
    B: ServiceFactory<A::Response, Config = A::Config, Error = A::Error, InitError = A::InitError>,
 | 
			
		||||
{
 | 
			
		||||
    fn clone(&self) -> Self {
 | 
			
		||||
        Self {
 | 
			
		||||
| 
						 | 
				
			
			@ -334,9 +314,8 @@ mod tests {
 | 
			
		|||
    async fn test_new_service() {
 | 
			
		||||
        let cnt = Rc::new(Cell::new(0));
 | 
			
		||||
        let cnt2 = cnt.clone();
 | 
			
		||||
        let new_srv =
 | 
			
		||||
            pipeline_factory(fn_factory(move || ready(Ok::<_, ()>(Srv1(cnt2.clone())))))
 | 
			
		||||
                .and_then(move || ready(Ok(Srv2(cnt.clone()))));
 | 
			
		||||
        let new_srv = pipeline_factory(fn_factory(move || ready(Ok::<_, ()>(Srv1(cnt2.clone())))))
 | 
			
		||||
            .and_then(move || ready(Ok(Srv2(cnt.clone()))));
 | 
			
		||||
 | 
			
		||||
        let srv = new_srv.new_service(()).await.unwrap();
 | 
			
		||||
        let res = srv.call("srv1").await;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -140,8 +140,7 @@ where
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<SF, F, Fut, Req, In, Res, Err> ServiceFactory<Req>
 | 
			
		||||
    for ApplyFactory<SF, F, Req, In, Res, Err>
 | 
			
		||||
impl<SF, F, Fut, Req, In, Res, Err> ServiceFactory<Req> for ApplyFactory<SF, F, Req, In, Res, Err>
 | 
			
		||||
where
 | 
			
		||||
    SF: ServiceFactory<In, Error = Err>,
 | 
			
		||||
    F: Fn(Req, &SF::Service) -> Fut + Clone,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -198,8 +198,7 @@ pin_project! {
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<SF, Req, F, Cfg, Fut, S> Future
 | 
			
		||||
    for ApplyConfigServiceFactoryResponse<SF, Req, F, Cfg, Fut, S>
 | 
			
		||||
impl<SF, Req, F, Cfg, Fut, S> Future for ApplyConfigServiceFactoryResponse<SF, Req, F, Cfg, Fut, S>
 | 
			
		||||
where
 | 
			
		||||
    SF: ServiceFactory<Req, Config = ()>,
 | 
			
		||||
    SF::InitError: From<SF::Error>,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -91,8 +91,7 @@ type Inner<C, Req, Res, Err, InitErr> = Box<
 | 
			
		|||
    >,
 | 
			
		||||
>;
 | 
			
		||||
 | 
			
		||||
impl<C, Req, Res, Err, InitErr> ServiceFactory<Req>
 | 
			
		||||
    for BoxServiceFactory<C, Req, Res, Err, InitErr>
 | 
			
		||||
impl<C, Req, Res, Err, InitErr> ServiceFactory<Req> for BoxServiceFactory<C, Req, Res, Err, InitErr>
 | 
			
		||||
where
 | 
			
		||||
    Req: 'static,
 | 
			
		||||
    Res: 'static,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,9 +3,7 @@ use core::{future::Future, marker::PhantomData};
 | 
			
		|||
use crate::{ok, IntoService, IntoServiceFactory, Ready, Service, ServiceFactory};
 | 
			
		||||
 | 
			
		||||
/// Create `ServiceFactory` for function that can act as a `Service`
 | 
			
		||||
pub fn fn_service<F, Fut, Req, Res, Err, Cfg>(
 | 
			
		||||
    f: F,
 | 
			
		||||
) -> FnServiceFactory<F, Fut, Req, Res, Err, Cfg>
 | 
			
		||||
pub fn fn_service<F, Fut, Req, Res, Err, Cfg>(f: F) -> FnServiceFactory<F, Fut, Req, Res, Err, Cfg>
 | 
			
		||||
where
 | 
			
		||||
    F: Fn(Req) -> Fut + Clone,
 | 
			
		||||
    Fut: Future<Output = Result<Res, Err>>,
 | 
			
		||||
| 
						 | 
				
			
			@ -48,9 +46,7 @@ where
 | 
			
		|||
///     Ok(())
 | 
			
		||||
/// }
 | 
			
		||||
/// ```
 | 
			
		||||
pub fn fn_factory<F, Cfg, Srv, Req, Fut, Err>(
 | 
			
		||||
    f: F,
 | 
			
		||||
) -> FnServiceNoConfig<F, Cfg, Srv, Req, Fut, Err>
 | 
			
		||||
pub fn fn_factory<F, Cfg, Srv, Req, Fut, Err>(f: F) -> FnServiceNoConfig<F, Cfg, Srv, Req, Fut, Err>
 | 
			
		||||
where
 | 
			
		||||
    F: Fn() -> Fut,
 | 
			
		||||
    Fut: Future<Output = Result<Srv, Err>>,
 | 
			
		||||
| 
						 | 
				
			
			@ -265,8 +261,7 @@ where
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<F, Fut, Cfg, Srv, Req, Err> ServiceFactory<Req>
 | 
			
		||||
    for FnServiceConfig<F, Fut, Cfg, Srv, Req, Err>
 | 
			
		||||
impl<F, Fut, Cfg, Srv, Req, Err> ServiceFactory<Req> for FnServiceConfig<F, Fut, Cfg, Srv, Req, Err>
 | 
			
		||||
where
 | 
			
		||||
    F: Fn(Cfg) -> Fut,
 | 
			
		||||
    Fut: Future<Output = Result<Srv, Err>>,
 | 
			
		||||
| 
						 | 
				
			
			@ -404,9 +399,8 @@ mod tests {
 | 
			
		|||
            ok::<_, Rc<u8>>(fn_service(|_: Rc<u8>| ok::<_, Rc<u8>>(Rc::new(0u8))))
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        let fac_2 = fn_factory(|| {
 | 
			
		||||
            ok::<_, Rc<u8>>(fn_service(|_: Rc<u8>| ok::<_, Rc<u8>>(Rc::new(0u8))))
 | 
			
		||||
        });
 | 
			
		||||
        let fac_2 =
 | 
			
		||||
            fn_factory(|| ok::<_, Rc<u8>>(fn_service(|_: Rc<u8>| ok::<_, Rc<u8>>(Rc::new(0u8)))));
 | 
			
		||||
 | 
			
		||||
        fn is_send<T: Send + Sync + Clone>(_: &T) {}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,14 +33,16 @@ mod then;
 | 
			
		|||
mod transform;
 | 
			
		||||
mod transform_err;
 | 
			
		||||
 | 
			
		||||
pub use self::apply::{apply_fn, apply_fn_factory};
 | 
			
		||||
pub use self::apply_cfg::{apply_cfg, apply_cfg_factory};
 | 
			
		||||
pub use self::ext::{ServiceExt, ServiceFactoryExt, TransformExt};
 | 
			
		||||
pub use self::fn_service::{fn_factory, fn_factory_with_config, fn_service};
 | 
			
		||||
pub use self::map_config::{map_config, unit_config};
 | 
			
		||||
#[allow(unused_imports)]
 | 
			
		||||
use self::ready::{err, ok, ready, Ready};
 | 
			
		||||
pub use self::transform::{apply, ApplyTransform, Transform};
 | 
			
		||||
pub use self::{
 | 
			
		||||
    apply::{apply_fn, apply_fn_factory},
 | 
			
		||||
    apply_cfg::{apply_cfg, apply_cfg_factory},
 | 
			
		||||
    ext::{ServiceExt, ServiceFactoryExt, TransformExt},
 | 
			
		||||
    fn_service::{fn_factory, fn_factory_with_config, fn_service},
 | 
			
		||||
    map_config::{map_config, unit_config},
 | 
			
		||||
    transform::{apply, ApplyTransform, Transform},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/// An asynchronous operation from `Request` to a `Response`.
 | 
			
		||||
///
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -206,8 +206,7 @@ mod tests {
 | 
			
		|||
 | 
			
		||||
    use super::*;
 | 
			
		||||
    use crate::{
 | 
			
		||||
        err, ok, IntoServiceFactory, Ready, Service, ServiceExt, ServiceFactory,
 | 
			
		||||
        ServiceFactoryExt,
 | 
			
		||||
        err, ok, IntoServiceFactory, Ready, Service, ServiceExt, ServiceFactory, ServiceFactoryExt,
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    struct Srv;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,12 +6,14 @@ use core::{
 | 
			
		|||
    task::{Context, Poll},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
use crate::and_then::{AndThenService, AndThenServiceFactory};
 | 
			
		||||
use crate::map::{Map, MapServiceFactory};
 | 
			
		||||
use crate::map_err::{MapErr, MapErrServiceFactory};
 | 
			
		||||
use crate::map_init_err::MapInitErr;
 | 
			
		||||
use crate::then::{ThenService, ThenServiceFactory};
 | 
			
		||||
use crate::{IntoService, IntoServiceFactory, Service, ServiceFactory};
 | 
			
		||||
use crate::{
 | 
			
		||||
    and_then::{AndThenService, AndThenServiceFactory},
 | 
			
		||||
    map::{Map, MapServiceFactory},
 | 
			
		||||
    map_err::{MapErr, MapErrServiceFactory},
 | 
			
		||||
    map_init_err::MapInitErr,
 | 
			
		||||
    then::{ThenService, ThenServiceFactory},
 | 
			
		||||
    IntoService, IntoServiceFactory, Service, ServiceFactory,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/// Construct new pipeline with one service in pipeline chain.
 | 
			
		||||
pub(crate) fn pipeline<I, S, Req>(service: I) -> Pipeline<S, Req>
 | 
			
		||||
| 
						 | 
				
			
			@ -252,10 +254,7 @@ where
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /// Map this service's error to a different error, returning a new service.
 | 
			
		||||
    pub fn map_err<F, E>(
 | 
			
		||||
        self,
 | 
			
		||||
        f: F,
 | 
			
		||||
    ) -> PipelineFactory<MapErrServiceFactory<SF, Req, F, E>, Req>
 | 
			
		||||
    pub fn map_err<F, E>(self, f: F) -> PipelineFactory<MapErrServiceFactory<SF, Req, F, E>, Req>
 | 
			
		||||
    where
 | 
			
		||||
        Self: Sized,
 | 
			
		||||
        F: Fn(SF::Error) -> E + Clone,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,8 +23,7 @@ use actix_utils::{
 | 
			
		|||
};
 | 
			
		||||
use pin_project_lite::pin_project;
 | 
			
		||||
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
 | 
			
		||||
use tokio_rustls::rustls::ServerConfig;
 | 
			
		||||
use tokio_rustls::{Accept, TlsAcceptor};
 | 
			
		||||
use tokio_rustls::{rustls::ServerConfig, Accept, TlsAcceptor};
 | 
			
		||||
 | 
			
		||||
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,10 +33,12 @@ pub mod rustls;
 | 
			
		|||
#[cfg(feature = "native-tls")]
 | 
			
		||||
pub mod native_tls;
 | 
			
		||||
 | 
			
		||||
pub use self::connection::Connection;
 | 
			
		||||
pub use self::connector::{Connector, ConnectorService};
 | 
			
		||||
pub use self::error::ConnectError;
 | 
			
		||||
pub use self::host::Host;
 | 
			
		||||
pub use self::info::ConnectInfo;
 | 
			
		||||
pub use self::resolve::Resolve;
 | 
			
		||||
pub use self::resolver::{Resolver, ResolverService};
 | 
			
		||||
pub use self::{
 | 
			
		||||
    connection::Connection,
 | 
			
		||||
    connector::{Connector, ConnectorService},
 | 
			
		||||
    error::ConnectError,
 | 
			
		||||
    host::Host,
 | 
			
		||||
    info::ConnectInfo,
 | 
			
		||||
    resolve::Resolve,
 | 
			
		||||
    resolver::{Resolver, ResolverService},
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,8 +19,7 @@ use crate::connect::{Connection, Host};
 | 
			
		|||
pub mod reexports {
 | 
			
		||||
    //! Re-exports from `native-tls` and `tokio-native-tls` that are useful for connectors.
 | 
			
		||||
 | 
			
		||||
    pub use tokio_native_tls::native_tls::TlsConnector;
 | 
			
		||||
    pub use tokio_native_tls::TlsStream as AsyncTlsStream;
 | 
			
		||||
    pub use tokio_native_tls::{native_tls::TlsConnector, TlsStream as AsyncTlsStream};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Connector service and factory using `native-tls`.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,9 +22,7 @@ use crate::connect::{Connection, Host};
 | 
			
		|||
pub mod reexports {
 | 
			
		||||
    //! Re-exports from `openssl` and `tokio-openssl` that are useful for connectors.
 | 
			
		||||
 | 
			
		||||
    pub use openssl::ssl::{
 | 
			
		||||
        Error, HandshakeError, SslConnector, SslConnectorBuilder, SslMethod,
 | 
			
		||||
    };
 | 
			
		||||
    pub use openssl::ssl::{Error, HandshakeError, SslConnector, SslConnectorBuilder, SslMethod};
 | 
			
		||||
    pub use tokio_openssl::SslStream as AsyncSslStream;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,9 +15,11 @@ use actix_rt::net::ActixStream;
 | 
			
		|||
use actix_service::{Service, ServiceFactory};
 | 
			
		||||
use actix_utils::future::{ok, Ready};
 | 
			
		||||
use futures_core::ready;
 | 
			
		||||
use tokio_rustls::rustls::{client::ServerName, OwnedTrustAnchor, RootCertStore};
 | 
			
		||||
use tokio_rustls::{client::TlsStream as AsyncTlsStream, rustls::ClientConfig};
 | 
			
		||||
use tokio_rustls::{Connect as RustlsConnect, TlsConnector as RustlsTlsConnector};
 | 
			
		||||
use tokio_rustls::{
 | 
			
		||||
    client::TlsStream as AsyncTlsStream,
 | 
			
		||||
    rustls::{client::ServerName, ClientConfig, OwnedTrustAnchor, RootCertStore},
 | 
			
		||||
    Connect as RustlsConnect, TlsConnector as RustlsTlsConnector,
 | 
			
		||||
};
 | 
			
		||||
use tracing::trace;
 | 
			
		||||
use webpki_roots::TLS_SERVER_ROOTS;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -26,8 +28,7 @@ use crate::connect::{Connection, Host};
 | 
			
		|||
pub mod reexports {
 | 
			
		||||
    //! Re-exports from `rustls` and `webpki_roots` that are useful for connectors.
 | 
			
		||||
 | 
			
		||||
    pub use tokio_rustls::client::TlsStream as AsyncTlsStream;
 | 
			
		||||
    pub use tokio_rustls::rustls::ClientConfig;
 | 
			
		||||
    pub use tokio_rustls::{client::TlsStream as AsyncTlsStream, rustls::ClientConfig};
 | 
			
		||||
    pub use webpki_roots::TLS_SERVER_ROOTS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,11 +17,9 @@ use actix_utils::future::ok;
 | 
			
		|||
use tokio_rustls::rustls::{Certificate, ClientConfig, RootCertStore, ServerName};
 | 
			
		||||
 | 
			
		||||
fn new_cert_and_key() -> (String, String) {
 | 
			
		||||
    let cert = rcgen::generate_simple_self_signed(vec![
 | 
			
		||||
        "127.0.0.1".to_owned(),
 | 
			
		||||
        "localhost".to_owned(),
 | 
			
		||||
    ])
 | 
			
		||||
    .unwrap();
 | 
			
		||||
    let cert =
 | 
			
		||||
        rcgen::generate_simple_self_signed(vec!["127.0.0.1".to_owned(), "localhost".to_owned()])
 | 
			
		||||
            .unwrap();
 | 
			
		||||
 | 
			
		||||
    let key = cert.serialize_private_key_pem();
 | 
			
		||||
    let cert = cert.serialize_pem().unwrap();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,19 +14,19 @@ use std::io::{BufReader, Write};
 | 
			
		|||
use actix_rt::net::TcpStream;
 | 
			
		||||
use actix_server::TestServer;
 | 
			
		||||
use actix_service::ServiceFactoryExt as _;
 | 
			
		||||
use actix_tls::accept::rustls::{Acceptor, TlsStream};
 | 
			
		||||
use actix_tls::connect::openssl::reexports::SslConnector;
 | 
			
		||||
use actix_tls::{
 | 
			
		||||
    accept::rustls::{Acceptor, TlsStream},
 | 
			
		||||
    connect::openssl::reexports::SslConnector,
 | 
			
		||||
};
 | 
			
		||||
use actix_utils::future::ok;
 | 
			
		||||
use rustls_pemfile::{certs, pkcs8_private_keys};
 | 
			
		||||
use tls_openssl::ssl::SslVerifyMode;
 | 
			
		||||
use tokio_rustls::rustls::{self, Certificate, PrivateKey, ServerConfig};
 | 
			
		||||
 | 
			
		||||
fn new_cert_and_key() -> (String, String) {
 | 
			
		||||
    let cert = rcgen::generate_simple_self_signed(vec![
 | 
			
		||||
        "127.0.0.1".to_owned(),
 | 
			
		||||
        "localhost".to_owned(),
 | 
			
		||||
    ])
 | 
			
		||||
    .unwrap();
 | 
			
		||||
    let cert =
 | 
			
		||||
        rcgen::generate_simple_self_signed(vec!["127.0.0.1".to_owned(), "localhost".to_owned()])
 | 
			
		||||
            .unwrap();
 | 
			
		||||
 | 
			
		||||
    let key = cert.serialize_private_key_pem();
 | 
			
		||||
    let cert = cert.serialize_pem().unwrap();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -51,8 +51,7 @@ async fn custom_resolver_connect() {
 | 
			
		|||
 | 
			
		||||
    use trust_dns_resolver::TokioAsyncResolver;
 | 
			
		||||
 | 
			
		||||
    let srv =
 | 
			
		||||
        TestServer::start(|| fn_service(|_io: TcpStream| async { Ok::<_, io::Error>(()) }));
 | 
			
		||||
    let srv = TestServer::start(|| fn_service(|_io: TcpStream| async { Ok::<_, io::Error>(()) }));
 | 
			
		||||
 | 
			
		||||
    struct MyResolver {
 | 
			
		||||
        trust_dns: TokioAsyncResolver,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -118,9 +118,11 @@ where
 | 
			
		|||
 | 
			
		||||
#[cfg(test)]
 | 
			
		||||
mod test {
 | 
			
		||||
    use std::cell::RefCell;
 | 
			
		||||
    use std::collections::{BTreeMap, BTreeSet};
 | 
			
		||||
    use std::sync::{Arc, RwLock};
 | 
			
		||||
    use std::{
 | 
			
		||||
        cell::RefCell,
 | 
			
		||||
        collections::{BTreeMap, BTreeSet},
 | 
			
		||||
        sync::{Arc, RwLock},
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    use actix_service::{fn_factory, fn_service};
 | 
			
		||||
    use slab::Slab;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,8 @@ mod either;
 | 
			
		|||
mod poll_fn;
 | 
			
		||||
mod ready;
 | 
			
		||||
 | 
			
		||||
pub use self::either::Either;
 | 
			
		||||
pub use self::poll_fn::{poll_fn, PollFn};
 | 
			
		||||
pub use self::ready::{err, ok, ready, Ready};
 | 
			
		||||
pub use self::{
 | 
			
		||||
    either::Either,
 | 
			
		||||
    poll_fn::{poll_fn, PollFn},
 | 
			
		||||
    ready::{err, ok, ready, Ready},
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -253,8 +253,10 @@ impl fmt::Display for ByteString {
 | 
			
		|||
mod serde {
 | 
			
		||||
    use alloc::string::String;
 | 
			
		||||
 | 
			
		||||
    use serde::de::{Deserialize, Deserializer};
 | 
			
		||||
    use serde::ser::{Serialize, Serializer};
 | 
			
		||||
    use serde::{
 | 
			
		||||
        de::{Deserialize, Deserializer},
 | 
			
		||||
        ser::{Serialize, Serializer},
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    use super::ByteString;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,2 +0,0 @@
 | 
			
		|||
max_width = 96
 | 
			
		||||
group_imports = "StdExternalCrate"
 | 
			
		||||
		Loading…
	
		Reference in New Issue