mirror of
https://github.com/fafhrd91/actix-net
synced 2025-03-20 17:15:17 +01:00
renamed boxed service
This commit is contained in:
parent
905d058454
commit
1fddd1e75b
@ -1,5 +1,21 @@
|
|||||||
# Changes
|
# 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
|
## [0.4.2] - 2019-08-27
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-service"
|
name = "actix-service"
|
||||||
version = "1.0.0-alpha.1"
|
version = "1.0.0-alpha.2"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix Service"
|
description = "Actix Service"
|
||||||
keywords = ["network", "framework", "async", "futures"]
|
keywords = ["network", "framework", "async", "futures"]
|
||||||
|
@ -1,26 +1,18 @@
|
|||||||
use std::task::{Context, Poll};
|
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<Req, Res, Err> = Box<
|
pub type BoxService<Req, Res, Err> =
|
||||||
dyn Service<
|
Box<dyn Service<Request = Req, Response = Res, Error = Err, Future = BoxFuture<Res, Err>>>;
|
||||||
Request = Req,
|
|
||||||
Response = Res,
|
|
||||||
Error = Err,
|
|
||||||
Future = BoxedServiceResponse<Res, Err>,
|
|
||||||
>,
|
|
||||||
>;
|
|
||||||
|
|
||||||
pub type BoxedServiceResponse<Res, Err> = LocalBoxFuture<'static, Result<Res, Err>>;
|
pub struct BoxServiceFactory<C, Req, Res, Err, InitErr>(Inner<C, Req, Res, Err, InitErr>);
|
||||||
|
|
||||||
pub struct BoxedNewService<C, Req, Res, Err, InitErr>(Inner<C, Req, Res, Err, InitErr>);
|
|
||||||
|
|
||||||
/// Create boxed new service
|
/// Create boxed new service
|
||||||
pub fn factory<T>(
|
pub fn factory<T>(
|
||||||
factory: T,
|
factory: T,
|
||||||
) -> BoxedNewService<T::Config, T::Request, T::Response, T::Error, T::InitError>
|
) -> BoxServiceFactory<T::Config, T::Request, T::Response, T::Error, T::InitError>
|
||||||
where
|
where
|
||||||
T: ServiceFactory + 'static,
|
T: ServiceFactory + 'static,
|
||||||
T::Request: 'static,
|
T::Request: 'static,
|
||||||
@ -30,14 +22,14 @@ where
|
|||||||
T::Error: 'static,
|
T::Error: 'static,
|
||||||
T::InitError: 'static,
|
T::InitError: 'static,
|
||||||
{
|
{
|
||||||
BoxedNewService(Box::new(FactoryWrapper {
|
BoxServiceFactory(Box::new(FactoryWrapper {
|
||||||
factory,
|
factory,
|
||||||
_t: std::marker::PhantomData,
|
_t: std::marker::PhantomData,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create boxed service
|
/// Create boxed service
|
||||||
pub fn service<T>(service: T) -> BoxedService<T::Request, T::Response, T::Error>
|
pub fn service<T>(service: T) -> BoxService<T::Request, T::Response, T::Error>
|
||||||
where
|
where
|
||||||
T: Service + 'static,
|
T: Service + 'static,
|
||||||
T::Future: 'static,
|
T::Future: 'static,
|
||||||
@ -52,12 +44,12 @@ type Inner<C, Req, Res, Err, InitErr> = Box<
|
|||||||
Response = Res,
|
Response = Res,
|
||||||
Error = Err,
|
Error = Err,
|
||||||
InitError = InitErr,
|
InitError = InitErr,
|
||||||
Service = BoxedService<Req, Res, Err>,
|
Service = BoxService<Req, Res, Err>,
|
||||||
Future = LocalBoxFuture<'static, Result<BoxedService<Req, Res, Err>, InitErr>>,
|
Future = BoxFuture<BoxService<Req, Res, Err>, InitErr>,
|
||||||
>,
|
>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
impl<C, Req, Res, Err, InitErr> ServiceFactory for BoxedNewService<C, Req, Res, Err, InitErr>
|
impl<C, Req, Res, Err, InitErr> ServiceFactory for BoxServiceFactory<C, Req, Res, Err, InitErr>
|
||||||
where
|
where
|
||||||
Req: 'static,
|
Req: 'static,
|
||||||
Res: 'static,
|
Res: 'static,
|
||||||
@ -69,9 +61,9 @@ where
|
|||||||
type Error = Err;
|
type Error = Err;
|
||||||
type InitError = InitErr;
|
type InitError = InitErr;
|
||||||
type Config = C;
|
type Config = C;
|
||||||
type Service = BoxedService<Req, Res, Err>;
|
type Service = BoxService<Req, Res, Err>;
|
||||||
|
|
||||||
type Future = LocalBoxFuture<'static, Result<Self::Service, InitErr>>;
|
type Future = BoxFuture<Self::Service, InitErr>;
|
||||||
|
|
||||||
fn new_service(&self, cfg: &C) -> Self::Future {
|
fn new_service(&self, cfg: &C) -> Self::Future {
|
||||||
self.0.new_service(cfg)
|
self.0.new_service(cfg)
|
||||||
@ -105,14 +97,15 @@ where
|
|||||||
type Error = Err;
|
type Error = Err;
|
||||||
type InitError = InitErr;
|
type InitError = InitErr;
|
||||||
type Config = C;
|
type Config = C;
|
||||||
type Service = BoxedService<Req, Res, Err>;
|
type Service = BoxService<Req, Res, Err>;
|
||||||
type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>;
|
type Future = BoxFuture<Self::Service, Self::InitError>;
|
||||||
|
|
||||||
fn new_service(&self, cfg: &C) -> Self::Future {
|
fn new_service(&self, cfg: &C) -> Self::Future {
|
||||||
self.factory
|
Box::pin(
|
||||||
.new_service(cfg)
|
self.factory
|
||||||
.map(|res| res.map(ServiceWrapper::boxed))
|
.new_service(cfg)
|
||||||
.boxed_local()
|
.map(|res| res.map(ServiceWrapper::boxed)),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +116,7 @@ where
|
|||||||
T: Service + 'static,
|
T: Service + 'static,
|
||||||
T::Future: 'static,
|
T::Future: 'static,
|
||||||
{
|
{
|
||||||
fn boxed(service: T) -> BoxedService<T::Request, T::Response, T::Error> {
|
fn boxed(service: T) -> BoxService<T::Request, T::Response, T::Error> {
|
||||||
Box::new(ServiceWrapper(service))
|
Box::new(ServiceWrapper(service))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,13 +129,13 @@ where
|
|||||||
type Request = Req;
|
type Request = Req;
|
||||||
type Response = Res;
|
type Response = Res;
|
||||||
type Error = Err;
|
type Error = Err;
|
||||||
type Future = LocalBoxFuture<'static, Result<Res, Err>>;
|
type Future = BoxFuture<Res, Err>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, ctx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
fn poll_ready(&mut self, ctx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
self.0.poll_ready(ctx)
|
self.0.poll_ready(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self, req: Self::Request) -> Self::Future {
|
fn call(&mut self, req: Self::Request) -> Self::Future {
|
||||||
self.0.call(req).boxed_local()
|
Box::pin(self.0.call(req))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
use std::pin::Pin;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::task::{self, Context, Poll};
|
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::pipeline::{pipeline, pipeline_factory, Pipeline, PipelineFactory};
|
||||||
pub use self::transform::{apply, Transform};
|
pub use self::transform::{apply, Transform};
|
||||||
|
|
||||||
|
pub type BoxFuture<I, E> = Pin<Box<dyn Future<Output = Result<I, E>>>>;
|
||||||
|
|
||||||
/// An asynchronous function from `Request` to a `Response`.
|
/// An asynchronous function from `Request` to a `Response`.
|
||||||
pub trait Service {
|
pub trait Service {
|
||||||
/// Requests handled by the service.
|
/// Requests handled by the service.
|
||||||
|
@ -211,7 +211,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use actix_service::Service;
|
use actix_service::Service;
|
||||||
use futures::channel::oneshot;
|
use futures::channel::oneshot;
|
||||||
use futures::future::{lazy, LocalBoxFuture};
|
use futures::future::{lazy, FutureExt, LocalBoxFuture};
|
||||||
|
|
||||||
struct Srv;
|
struct Srv;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user