1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-23 21:51:06 +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
reorder_imports = true
wrap_comments = true
fn_args_density = "Compressed"
#wrap_comments = true
#fn_args_density = "Compressed"
#use_small_heuristics = false

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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