1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-23 22:51:07 +01:00

update tests

This commit is contained in:
Nikolay Kim 2018-11-29 17:17:02 -10:00
parent 1b1ae01b5a
commit 8108f19580
9 changed files with 43 additions and 37 deletions

View File

@ -1,5 +1,5 @@
max_width = 96 max_width = 96
reorder_imports = true reorder_imports = true
wrap_comments = true #wrap_comments = true
fn_args_density = "Compressed" #fn_args_density = "Compressed"
#use_small_heuristics = false #use_small_heuristics = false

View File

@ -173,19 +173,18 @@ impl Connector {
Connector { resolver } Connector { resolver }
} }
// /// Create new default connector service /// Create new default connector service
// pub fn new_service_with_config<E>( pub fn new_service_with_config<E>(
// cfg: ResolverConfig, cfg: ResolverConfig,
// opts: ResolverOpts, opts: ResolverOpts,
// ) -> impl NewService< ) -> impl NewService<
// Connect, Connect,
// Response = (Connect, TcpStream), Response = (Connect, TcpStream),
// Error = ConnectorError, Error = ConnectorError,
// InitError = E, InitError = E,
// Service = impl Service<Connect, Response = (Connect, TcpStream), Error = ConnectorError> + Clone, > + Clone {
// > + Clone { move || -> FutureResult<Connector, E> { ok(Connector::new(cfg.clone(), opts)) }
// move || -> FutureResult<Connector, E> { ok(Connector::new(cfg.clone(), opts)) } }
// }
} }
impl Clone for Connector { impl Clone for Connector {

View File

@ -26,7 +26,6 @@ impl<A, B> AndThen<A, B> {
impl<A, B> Clone for AndThen<A, B> impl<A, B> Clone for AndThen<A, B>
where where
A: Clone, A: Clone,
B: Clone,
{ {
fn clone(&self) -> Self { fn clone(&self) -> Self {
AndThen { AndThen {
@ -223,8 +222,7 @@ mod tests {
use service::{NewServiceExt, Service, ServiceExt}; use service::{NewServiceExt, Service, ServiceExt};
struct Srv1(Rc<Cell<usize>>); struct Srv1(Rc<Cell<usize>>);
impl Service for Srv1 { impl Service<&'static str> for Srv1 {
type Request = &'static str;
type Response = &'static str; type Response = &'static str;
type Error = (); type Error = ();
type Future = FutureResult<Self::Response, ()>; type Future = FutureResult<Self::Response, ()>;
@ -234,7 +232,7 @@ mod tests {
Ok(Async::Ready(())) Ok(Async::Ready(()))
} }
fn call(&mut self, req: Self::Request) -> Self::Future { fn call(&mut self, req: &'static str) -> Self::Future {
ok(req) ok(req)
} }
} }
@ -242,8 +240,7 @@ mod tests {
#[derive(Clone)] #[derive(Clone)]
struct Srv2(Rc<Cell<usize>>); struct Srv2(Rc<Cell<usize>>);
impl Service for Srv2 { impl Service<&'static str> for Srv2 {
type Request = &'static str;
type Response = (&'static str, &'static str); type Response = (&'static str, &'static str);
type Error = (); type Error = ();
type Future = FutureResult<Self::Response, ()>; type Future = FutureResult<Self::Response, ()>;
@ -253,7 +250,7 @@ mod tests {
Ok(Async::Ready(())) Ok(Async::Ready(()))
} }
fn call(&mut self, req: Self::Request) -> Self::Future { fn call(&mut self, req: &'static str) -> Self::Future {
ok((req, "srv2")) ok((req, "srv2"))
} }
} }

View File

@ -177,8 +177,7 @@ mod tests {
#[derive(Clone)] #[derive(Clone)]
struct Srv; struct Srv;
impl Service for Srv { impl Service<()> for Srv {
type Request = ();
type Response = (); type Response = ();
type Error = (); type Error = ();
type Future = FutureResult<(), ()>; type Future = FutureResult<(), ()>;

View File

@ -162,8 +162,7 @@ mod tests {
use service::{IntoNewService, NewServiceExt, Service, ServiceExt}; use service::{IntoNewService, NewServiceExt, Service, ServiceExt};
struct Srv; struct Srv;
impl Service for Srv { impl Service<()> for Srv {
type Request = ();
type Response = (); type Response = ();
type Error = (); type Error = ();
type Future = FutureResult<(), ()>; type Future = FutureResult<(), ()>;

View File

@ -192,8 +192,7 @@ mod tests {
use service::{IntoNewService, NewServiceExt, Service, ServiceExt}; use service::{IntoNewService, NewServiceExt, Service, ServiceExt};
struct Srv; struct Srv;
impl Service for Srv { impl Service<()> for Srv {
type Request = ();
type Response = (); type Response = ();
type Error = (); type Error = ();
type Future = FutureResult<(), ()>; type Future = FutureResult<(), ()>;

View File

@ -194,8 +194,7 @@ mod tests {
struct Srv; struct Srv;
impl Service for Srv { impl Service<()> for Srv {
type Request = ();
type Response = (); type Response = ();
type Error = (); type Error = ();
type Future = FutureResult<(), ()>; type Future = FutureResult<(), ()>;

View File

@ -231,6 +231,23 @@ pub trait NewServiceExt<Request>: NewService<Request> {
} }
} }
impl<F, R, E, S, Request> NewService<Request> for F
where
F: Fn() -> R,
R: IntoFuture<Item = S, Error = E>,
S: Service<Request>,
{
type Response = S::Response;
type Error = S::Error;
type Service = S;
type InitError = E;
type Future = R::Future;
fn new_service(&self) -> Self::Future {
(*self)().into_future()
}
}
impl<T: ?Sized, R> ServiceExt<R> for T where T: Service<R> {} impl<T: ?Sized, R> ServiceExt<R> for T where T: Service<R> {}
impl<T: ?Sized, R> NewServiceExt<R> for T where T: NewService<R> {} impl<T: ?Sized, R> NewServiceExt<R> for T where T: NewService<R> {}

View File

@ -26,7 +26,6 @@ impl<A, B> Then<A, B> {
impl<A, B> Clone for Then<A, B> impl<A, B> Clone for Then<A, B>
where where
A: Clone, A: Clone,
B: Clone,
{ {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Then { Then {
@ -231,8 +230,7 @@ mod tests {
#[derive(Clone)] #[derive(Clone)]
struct Srv1(Rc<Cell<usize>>); struct Srv1(Rc<Cell<usize>>);
impl Service for Srv1 { impl Service<Result<&'static str, &'static str>> for Srv1 {
type Request = Result<&'static str, &'static str>;
type Response = &'static str; type Response = &'static str;
type Error = (); type Error = ();
type Future = FutureResult<Self::Response, Self::Error>; type Future = FutureResult<Self::Response, Self::Error>;
@ -242,7 +240,7 @@ mod tests {
Ok(Async::Ready(())) Ok(Async::Ready(()))
} }
fn call(&mut self, req: Self::Request) -> Self::Future { fn call(&mut self, req: Result<&'static str, &'static str>) -> Self::Future {
match req { match req {
Ok(msg) => ok(msg), Ok(msg) => ok(msg),
Err(_) => err(()), Err(_) => err(()),
@ -252,8 +250,7 @@ mod tests {
struct Srv2(Rc<Cell<usize>>); struct Srv2(Rc<Cell<usize>>);
impl Service for Srv2 { impl Service<Result<&'static str, ()>> for Srv2 {
type Request = Result<&'static str, ()>;
type Response = (&'static str, &'static str); type Response = (&'static str, &'static str);
type Error = (); type Error = ();
type Future = FutureResult<Self::Response, ()>; type Future = FutureResult<Self::Response, ()>;
@ -263,7 +260,7 @@ mod tests {
Ok(Async::Ready(())) Ok(Async::Ready(()))
} }
fn call(&mut self, req: Self::Request) -> Self::Future { fn call(&mut self, req: Result<&'static str, ()>) -> Self::Future {
match req { match req {
Ok(msg) => ok((msg, "ok")), Ok(msg) => ok((msg, "ok")),
Err(()) => ok(("srv2", "err")), Err(()) => ok(("srv2", "err")),