From 1fddd1e75b4759fac98b120cda5f2c2ac1f85735 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 25 Nov 2019 18:18:00 +0600 Subject: [PATCH] renamed boxed service --- actix-service/CHANGES.md | 16 ++++++++++++ actix-service/Cargo.toml | 2 +- actix-service/src/boxed.rs | 53 +++++++++++++++++--------------------- actix-service/src/lib.rs | 3 +++ actix-utils/src/order.rs | 2 +- 5 files changed, 44 insertions(+), 32 deletions(-) diff --git a/actix-service/CHANGES.md b/actix-service/CHANGES.md index 859491b4..b3a7d488 100644 --- a/actix-service/CHANGES.md +++ b/actix-service/CHANGES.md @@ -1,5 +1,21 @@ # Changes +## [1.0.0-alpha.2] - 2019-11-xx + +### Renamed BoxedNewService/BoxedService to BoxServiceFactory/BoxService + + +## [1.0.0-alpha.1] - 2019-11-25 + +### Changed + +* Migraded to `std::future` + +* `NewService` renamed to `ServiceFactory` + +* Added `pipeline` and `pipeline_factory` function + + ## [0.4.2] - 2019-08-27 ### Fixed diff --git a/actix-service/Cargo.toml b/actix-service/Cargo.toml index 1303cb8a..c4204299 100644 --- a/actix-service/Cargo.toml +++ b/actix-service/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-service" -version = "1.0.0-alpha.1" +version = "1.0.0-alpha.2" authors = ["Nikolay Kim "] description = "Actix Service" keywords = ["network", "framework", "async", "futures"] diff --git a/actix-service/src/boxed.rs b/actix-service/src/boxed.rs index 78f1d79a..783d54c6 100644 --- a/actix-service/src/boxed.rs +++ b/actix-service/src/boxed.rs @@ -1,26 +1,18 @@ use std::task::{Context, Poll}; -use futures::future::{FutureExt, LocalBoxFuture}; +use futures::future::FutureExt; -use crate::{Service, ServiceFactory}; +use crate::{BoxFuture, Service, ServiceFactory}; -pub type BoxedService = Box< - dyn Service< - Request = Req, - Response = Res, - Error = Err, - Future = BoxedServiceResponse, - >, ->; +pub type BoxService = + Box>>; -pub type BoxedServiceResponse = LocalBoxFuture<'static, Result>; - -pub struct BoxedNewService(Inner); +pub struct BoxServiceFactory(Inner); /// Create boxed new service pub fn factory( factory: T, -) -> BoxedNewService +) -> BoxServiceFactory where T: ServiceFactory + 'static, T::Request: 'static, @@ -30,14 +22,14 @@ where T::Error: 'static, T::InitError: 'static, { - BoxedNewService(Box::new(FactoryWrapper { + BoxServiceFactory(Box::new(FactoryWrapper { factory, _t: std::marker::PhantomData, })) } /// Create boxed service -pub fn service(service: T) -> BoxedService +pub fn service(service: T) -> BoxService where T: Service + 'static, T::Future: 'static, @@ -52,12 +44,12 @@ type Inner = Box< Response = Res, Error = Err, InitError = InitErr, - Service = BoxedService, - Future = LocalBoxFuture<'static, Result, InitErr>>, + Service = BoxService, + Future = BoxFuture, InitErr>, >, >; -impl ServiceFactory for BoxedNewService +impl ServiceFactory for BoxServiceFactory where Req: 'static, Res: 'static, @@ -69,9 +61,9 @@ where type Error = Err; type InitError = InitErr; type Config = C; - type Service = BoxedService; + type Service = BoxService; - type Future = LocalBoxFuture<'static, Result>; + type Future = BoxFuture; fn new_service(&self, cfg: &C) -> Self::Future { self.0.new_service(cfg) @@ -105,14 +97,15 @@ where type Error = Err; type InitError = InitErr; type Config = C; - type Service = BoxedService; - type Future = LocalBoxFuture<'static, Result>; + type Service = BoxService; + type Future = BoxFuture; fn new_service(&self, cfg: &C) -> Self::Future { - self.factory - .new_service(cfg) - .map(|res| res.map(ServiceWrapper::boxed)) - .boxed_local() + Box::pin( + self.factory + .new_service(cfg) + .map(|res| res.map(ServiceWrapper::boxed)), + ) } } @@ -123,7 +116,7 @@ where T: Service + 'static, T::Future: 'static, { - fn boxed(service: T) -> BoxedService { + fn boxed(service: T) -> BoxService { Box::new(ServiceWrapper(service)) } } @@ -136,13 +129,13 @@ where type Request = Req; type Response = Res; type Error = Err; - type Future = LocalBoxFuture<'static, Result>; + type Future = BoxFuture; fn poll_ready(&mut self, ctx: &mut Context<'_>) -> Poll> { self.0.poll_ready(ctx) } fn call(&mut self, req: Self::Request) -> Self::Future { - self.0.call(req).boxed_local() + Box::pin(self.0.call(req)) } } diff --git a/actix-service/src/lib.rs b/actix-service/src/lib.rs index 84410534..790f4554 100644 --- a/actix-service/src/lib.rs +++ b/actix-service/src/lib.rs @@ -1,5 +1,6 @@ use std::cell::RefCell; use std::future::Future; +use std::pin::Pin; use std::rc::Rc; use std::sync::Arc; use std::task::{self, Context, Poll}; @@ -25,6 +26,8 @@ pub use self::map_config::{map_config, unit_config, MappedConfig}; pub use self::pipeline::{pipeline, pipeline_factory, Pipeline, PipelineFactory}; pub use self::transform::{apply, Transform}; +pub type BoxFuture = Pin>>>; + /// An asynchronous function from `Request` to a `Response`. pub trait Service { /// Requests handled by the service. diff --git a/actix-utils/src/order.rs b/actix-utils/src/order.rs index 12c30ace..6938ca41 100644 --- a/actix-utils/src/order.rs +++ b/actix-utils/src/order.rs @@ -211,7 +211,7 @@ mod tests { use super::*; use actix_service::Service; use futures::channel::oneshot; - use futures::future::{lazy, LocalBoxFuture}; + use futures::future::{lazy, FutureExt, LocalBoxFuture}; struct Srv;