Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Nov 30, 2018
1 parent 1b1ae01 commit 8108f19
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 37 deletions.
4 changes: 2 additions & 2 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -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
25 changes: 12 additions & 13 deletions src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 4 additions & 7 deletions src/service/and_then.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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, ()>;
Expand All @@ -234,16 +232,15 @@ 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)
}
}

#[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, ()>;
Expand All @@ -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"))
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/service/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<(), ()>;
Expand Down
3 changes: 1 addition & 2 deletions src/service/from_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<(), ()>;
Expand Down
3 changes: 1 addition & 2 deletions src/service/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<(), ()>;
Expand Down
3 changes: 1 addition & 2 deletions src/service/map_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<(), ()>;
Expand Down
17 changes: 17 additions & 0 deletions src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {}

Expand Down
11 changes: 4 additions & 7 deletions src/service/then.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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>;
Expand All @@ -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(()),
Expand All @@ -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, ()>;
Expand All @@ -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")),
Expand Down

0 comments on commit 8108f19

Please sign in to comment.