mirror of
https://github.com/fafhrd91/actix-net
synced 2025-08-15 06:45:56 +02:00
Compare commits
5 Commits
server-0.2
...
utils-0.2.
Author | SHA1 | Date | |
---|---|---|---|
|
6ea128fac5 | ||
|
a97d7f0ccf | ||
|
3d7daabdd7 | ||
|
32f4718880 | ||
|
b8f9bf4bc8 |
@@ -1,5 +1,14 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.2.2] - 2019-02-19
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
* Added `NewService` impl for `Rc<S> where S: NewService`
|
||||||
|
|
||||||
|
* Added `NewService` impl for `Arc<S> where S: NewService`
|
||||||
|
|
||||||
|
|
||||||
## [0.2.1] - 2019-02-03
|
## [0.2.1] - 2019-02-03
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-service"
|
name = "actix-service"
|
||||||
version = "0.2.1"
|
version = "0.2.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,3 +1,6 @@
|
|||||||
|
use std::rc::Rc;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use futures::{Future, IntoFuture, Poll};
|
use futures::{Future, IntoFuture, Poll};
|
||||||
|
|
||||||
mod and_then;
|
mod and_then;
|
||||||
@@ -377,6 +380,38 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<S> NewService for Rc<S>
|
||||||
|
where
|
||||||
|
S: NewService,
|
||||||
|
{
|
||||||
|
type Request = S::Request;
|
||||||
|
type Response = S::Response;
|
||||||
|
type Error = S::Error;
|
||||||
|
type Service = S::Service;
|
||||||
|
type InitError = S::InitError;
|
||||||
|
type Future = S::Future;
|
||||||
|
|
||||||
|
fn new_service(&self) -> S::Future {
|
||||||
|
self.as_ref().new_service()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S> NewService for Arc<S>
|
||||||
|
where
|
||||||
|
S: NewService,
|
||||||
|
{
|
||||||
|
type Request = S::Request;
|
||||||
|
type Response = S::Response;
|
||||||
|
type Error = S::Error;
|
||||||
|
type Service = S::Service;
|
||||||
|
type InitError = S::InitError;
|
||||||
|
type Future = S::Future;
|
||||||
|
|
||||||
|
fn new_service(&self) -> S::Future {
|
||||||
|
self.as_ref().new_service()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Trait for types that can be converted to a `Service`
|
/// Trait for types that can be converted to a `Service`
|
||||||
pub trait IntoService<T>
|
pub trait IntoService<T>
|
||||||
where
|
where
|
||||||
|
@@ -1,5 +1,28 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.2.4] - 2019-02-21
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
* Custom `BoxedNewService` implementation.
|
||||||
|
|
||||||
|
|
||||||
|
## [0.2.3] - 2019-02-21
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
* Add `BoxedNewService` and `BoxedService`
|
||||||
|
|
||||||
|
|
||||||
|
## [0.2.2] - 2019-02-11
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
* Add `Display` impl for `TimeoutError`
|
||||||
|
|
||||||
|
* Add `Display` impl for `InOrderError`
|
||||||
|
|
||||||
|
|
||||||
## [0.2.1] - 2019-02-06
|
## [0.2.1] - 2019-02-06
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-utils"
|
name = "actix-utils"
|
||||||
version = "0.2.1"
|
version = "0.2.4"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix utils - various actix net related services"
|
description = "Actix utils - various actix net related services"
|
||||||
keywords = ["network", "framework", "async", "futures"]
|
keywords = ["network", "framework", "async", "futures"]
|
||||||
@@ -18,12 +18,12 @@ name = "actix_utils"
|
|||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-service = "0.2.1"
|
actix-service = "0.2.2"
|
||||||
actix-codec = "0.1.0"
|
actix-codec = "0.1.0"
|
||||||
bytes = "0.4"
|
bytes = "0.4"
|
||||||
futures = "0.1"
|
futures = "0.1.24"
|
||||||
tokio-timer = "0.2.8"
|
tokio-timer = "0.2.8"
|
||||||
tokio-current-thread = "0.1"
|
tokio-current-thread = "0.1.4"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
123
actix-utils/src/boxed.rs
Normal file
123
actix-utils/src/boxed.rs
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
use actix_service::{NewService, Service};
|
||||||
|
use futures::{Future, Poll};
|
||||||
|
|
||||||
|
pub type BoxedService<Req, Res, Err> = Box<
|
||||||
|
Service<
|
||||||
|
Request = Req,
|
||||||
|
Response = Res,
|
||||||
|
Error = Err,
|
||||||
|
Future = Box<Future<Item = Res, Error = Err>>,
|
||||||
|
>,
|
||||||
|
>;
|
||||||
|
|
||||||
|
/// Create boxed new service
|
||||||
|
pub fn new_service<T>(
|
||||||
|
service: T,
|
||||||
|
) -> BoxedNewService<T::Request, T::Response, T::Error, T::InitError>
|
||||||
|
where
|
||||||
|
T: NewService + 'static,
|
||||||
|
T::Service: 'static,
|
||||||
|
{
|
||||||
|
BoxedNewService(Box::new(NewServiceWrapper(service)))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create boxed service
|
||||||
|
pub fn service<T>(service: T) -> BoxedService<T::Request, T::Response, T::Error>
|
||||||
|
where
|
||||||
|
T: Service + 'static,
|
||||||
|
T::Future: 'static,
|
||||||
|
{
|
||||||
|
Box::new(ServiceWrapper(service))
|
||||||
|
}
|
||||||
|
|
||||||
|
type Inner<Req, Res, Err, InitErr> = Box<
|
||||||
|
NewService<
|
||||||
|
Request = Req,
|
||||||
|
Response = Res,
|
||||||
|
Error = Err,
|
||||||
|
InitError = InitErr,
|
||||||
|
Service = BoxedService<Req, Res, Err>,
|
||||||
|
Future = Box<Future<Item = BoxedService<Req, Res, Err>, Error = InitErr>>,
|
||||||
|
>,
|
||||||
|
>;
|
||||||
|
|
||||||
|
pub struct BoxedNewService<Req, Res, Err, InitErr>(Inner<Req, Res, Err, InitErr>);
|
||||||
|
|
||||||
|
impl<Req, Res, Err, InitErr> NewService for BoxedNewService<Req, Res, Err, InitErr>
|
||||||
|
where
|
||||||
|
Req: 'static,
|
||||||
|
Res: 'static,
|
||||||
|
Err: 'static,
|
||||||
|
InitErr: 'static,
|
||||||
|
{
|
||||||
|
type Request = Req;
|
||||||
|
type Response = Res;
|
||||||
|
type Error = Err;
|
||||||
|
type InitError = InitErr;
|
||||||
|
type Service = BoxedService<Req, Res, Err>;
|
||||||
|
type Future = Box<Future<Item = Self::Service, Error = Self::InitError>>;
|
||||||
|
|
||||||
|
fn new_service(&self) -> Self::Future {
|
||||||
|
self.0.new_service()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct NewServiceWrapper<T: NewService>(T);
|
||||||
|
|
||||||
|
impl<T, Req, Res, Err, InitErr> NewService for NewServiceWrapper<T>
|
||||||
|
where
|
||||||
|
Req: 'static,
|
||||||
|
Res: 'static,
|
||||||
|
Err: 'static,
|
||||||
|
InitErr: 'static,
|
||||||
|
T: NewService<Request = Req, Response = Res, Error = Err, InitError = InitErr>,
|
||||||
|
T::Future: 'static,
|
||||||
|
T::Service: 'static,
|
||||||
|
<T::Service as Service>::Future: 'static,
|
||||||
|
{
|
||||||
|
type Request = Req;
|
||||||
|
type Response = Res;
|
||||||
|
type Error = Err;
|
||||||
|
type InitError = InitErr;
|
||||||
|
type Service = BoxedService<Req, Res, Err>;
|
||||||
|
type Future = Box<Future<Item = Self::Service, Error = Self::InitError>>;
|
||||||
|
|
||||||
|
fn new_service(&self) -> Self::Future {
|
||||||
|
Box::new(
|
||||||
|
self.0
|
||||||
|
.new_service()
|
||||||
|
.map(|service| ServiceWrapper::boxed(service)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ServiceWrapper<T: Service>(T);
|
||||||
|
|
||||||
|
impl<T> ServiceWrapper<T>
|
||||||
|
where
|
||||||
|
T: Service + 'static,
|
||||||
|
T::Future: 'static,
|
||||||
|
{
|
||||||
|
fn boxed(service: T) -> BoxedService<T::Request, T::Response, T::Error> {
|
||||||
|
Box::new(ServiceWrapper(service))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T, Req, Res, Err> Service for ServiceWrapper<T>
|
||||||
|
where
|
||||||
|
T: Service<Request = Req, Response = Res, Error = Err>,
|
||||||
|
T::Future: 'static,
|
||||||
|
{
|
||||||
|
type Request = Req;
|
||||||
|
type Response = Res;
|
||||||
|
type Error = Err;
|
||||||
|
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;
|
||||||
|
|
||||||
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
|
self.0.poll_ready()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn call(&mut self, req: Self::Request) -> Self::Future {
|
||||||
|
Box::new(self.0.call(req))
|
||||||
|
}
|
||||||
|
}
|
@@ -1,4 +1,5 @@
|
|||||||
//! Actix utils - various helper services
|
//! Actix utils - various helper services
|
||||||
|
pub mod boxed;
|
||||||
mod cell;
|
mod cell;
|
||||||
pub mod cloneable;
|
pub mod cloneable;
|
||||||
pub mod counter;
|
pub mod counter;
|
||||||
|
@@ -37,6 +37,15 @@ impl<E: fmt::Debug> fmt::Debug for InOrderError<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<E: fmt::Display> fmt::Display for InOrderError<E> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
InOrderError::Service(e) => e.fmt(f),
|
||||||
|
InOrderError::Disconnected => write!(f, "InOrder service disconnected"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// InOrder - The service will yield responses as they become available,
|
/// InOrder - The service will yield responses as they become available,
|
||||||
/// in the order that their originating requests were submitted to the service.
|
/// in the order that their originating requests were submitted to the service.
|
||||||
pub struct InOrder<S> {
|
pub struct InOrder<S> {
|
||||||
|
@@ -41,6 +41,15 @@ impl<E: fmt::Debug> fmt::Debug for TimeoutError<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<E: fmt::Display> fmt::Display for TimeoutError<E> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
TimeoutError::Service(e) => e.fmt(f),
|
||||||
|
TimeoutError::Timeout => write!(f, "Service call timeout"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<E: PartialEq> PartialEq for TimeoutError<E> {
|
impl<E: PartialEq> PartialEq for TimeoutError<E> {
|
||||||
fn eq(&self, other: &TimeoutError<E>) -> bool {
|
fn eq(&self, other: &TimeoutError<E>) -> bool {
|
||||||
match self {
|
match self {
|
||||||
|
Reference in New Issue
Block a user