Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NewService is generic over error #5

Merged
merged 4 commits into from
Sep 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ extern crate futures;

use futures::{Future, IntoFuture};

use std::io;
use std::rc::Rc;
use std::sync::Arc;

Expand Down Expand Up @@ -172,22 +171,26 @@ pub trait NewService {
/// The `Service` value created by this factory
type Instance: Service<Request = Self::Request, Response = Self::Response, Error = Self::Error>;

/// Errors produced while building a service.
type InitError;

/// The future of the `Service` instance.
type Future: Future<Item = Self::Instance, Error = io::Error>;
type Future: Future<Item = Self::Instance, Error = Self::InitError>;

/// Create and return a new service value asynchronously.
fn new_service(&self) -> Self::Future;
}

impl<F, R, S> NewService for F
impl<F, R, E, S> NewService for F
where F: Fn() -> R,
R: IntoFuture<Item = S, Error = io::Error>,
R: IntoFuture<Item = S, Error = E>,
S: Service,
{
type Request = S::Request;
type Response = S::Response;
type Error = S::Error;
type Instance = S;
type InitError = E;
type Future = R::Future;

fn new_service(&self) -> Self::Future {
Expand All @@ -200,6 +203,7 @@ impl<S: NewService + ?Sized> NewService for Arc<S> {
type Response = S::Response;
type Error = S::Error;
type Instance = S::Instance;
type InitError = S::InitError;
type Future = S::Future;

fn new_service(&self) -> Self::Future {
Expand All @@ -212,6 +216,7 @@ impl<S: NewService + ?Sized> NewService for Rc<S> {
type Response = S::Response;
type Error = S::Error;
type Instance = S::Instance;
type InitError = S::InitError;
type Future = S::Future;

fn new_service(&self) -> Self::Future {
Expand Down