1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-30 17:44:34 +01:00

change Either constructor

This commit is contained in:
Nikolay Kim 2019-05-14 17:32:50 -07:00
parent 837504c10f
commit 0a6cded975
3 changed files with 25 additions and 19 deletions

View File

@ -33,7 +33,7 @@ pub trait TowerServiceExt {
impl<S> TowerServiceExt for S { impl<S> TowerServiceExt for S {
fn compat<R>(self) -> TowerCompat<Self, R> fn compat<R>(self) -> TowerCompat<Self, R>
where where
Self: TowerService<R> + Sized Self: TowerService<R> + Sized,
{ {
TowerCompat::new(self) TowerCompat::new(self)
} }
@ -61,7 +61,7 @@ where
mod tests { mod tests {
use super::TowerServiceExt; use super::TowerServiceExt;
use actix_service::{Service as ActixService, ServiceExt, Transform}; use actix_service::{Service as ActixService, ServiceExt, Transform};
use futures::{future::FutureResult, Async, Poll, Future}; use futures::{future::FutureResult, Async, Future, Poll};
use tower_service::Service as TowerService; use tower_service::Service as TowerService;
struct RandomService; struct RandomService;
@ -182,10 +182,13 @@ mod tests {
fn tower_service_as_actix_service_can_be_transformed() { fn tower_service_as_actix_service_can_be_transformed() {
let transform = DoMath; let transform = DoMath;
let mut s = transform.new_transform(RandomService.compat()).wait().unwrap(); let mut s = transform
.new_transform(RandomService.compat())
.wait()
.unwrap();
assert_eq!(Ok(Async::Ready(())), s.poll_ready()); assert_eq!(Ok(Async::Ready(())), s.poll_ready());
assert_eq!(Ok(Async::Ready(68)), s.call(()).poll()); assert_eq!(Ok(Async::Ready(68)), s.call(()).poll());
} }
} }

View File

@ -1,5 +1,12 @@
# Changes # Changes
##[0.4.1] - 2019-05-xx
### Changed
* Change `Either` constructor
## [0.4.0] - 2019-05-11 ## [0.4.0] - 2019-05-11
### Changed ### Changed

View File

@ -57,25 +57,21 @@ pub struct Either<A, B> {
} }
impl<A, B> Either<A, B> { impl<A, B> Either<A, B> {
pub fn new_a<F>(srv: F) -> Either<A, ()> pub fn new<F1, F2>(srv_a: F1, srv_b: F2) -> Either<A, B>
where where
A: NewService, A: NewService,
F: IntoNewService<A>, B: NewService<
Config = A::Config,
Response = A::Response,
Error = A::Error,
InitError = A::InitError,
>,
F1: IntoNewService<A>,
F2: IntoNewService<B>,
{ {
Either { Either {
left: srv.into_new_service(), left: srv_a.into_new_service(),
right: (), right: srv_b.into_new_service(),
}
}
pub fn new_b<F>(srv: F) -> Either<(), B>
where
B: NewService,
F: IntoNewService<B>,
{
Either {
left: (),
right: srv.into_new_service(),
} }
} }
} }