NewService is generic over error (#5)
Previously, NewService required returning a future yielding io::Error as the error. This is not needed and is restrictive.
This commit is contained in:
parent
270ef5a2bd
commit
3a0212d460
13
src/lib.rs
13
src/lib.rs
|
@ -12,7 +12,6 @@ extern crate futures;
|
||||||
|
|
||||||
use futures::{Future, IntoFuture};
|
use futures::{Future, IntoFuture};
|
||||||
|
|
||||||
use std::io;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
@ -172,22 +171,26 @@ pub trait NewService {
|
||||||
/// The `Service` value created by this factory
|
/// The `Service` value created by this factory
|
||||||
type Instance: Service<Request = Self::Request, Response = Self::Response, Error = Self::Error>;
|
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.
|
/// 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.
|
/// Create and return a new service value asynchronously.
|
||||||
fn new_service(&self) -> Self::Future;
|
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,
|
where F: Fn() -> R,
|
||||||
R: IntoFuture<Item = S, Error = io::Error>,
|
R: IntoFuture<Item = S, Error = E>,
|
||||||
S: Service,
|
S: Service,
|
||||||
{
|
{
|
||||||
type Request = S::Request;
|
type Request = S::Request;
|
||||||
type Response = S::Response;
|
type Response = S::Response;
|
||||||
type Error = S::Error;
|
type Error = S::Error;
|
||||||
type Instance = S;
|
type Instance = S;
|
||||||
|
type InitError = E;
|
||||||
type Future = R::Future;
|
type Future = R::Future;
|
||||||
|
|
||||||
fn new_service(&self) -> Self::Future {
|
fn new_service(&self) -> Self::Future {
|
||||||
|
@ -200,6 +203,7 @@ impl<S: NewService + ?Sized> NewService for Arc<S> {
|
||||||
type Response = S::Response;
|
type Response = S::Response;
|
||||||
type Error = S::Error;
|
type Error = S::Error;
|
||||||
type Instance = S::Instance;
|
type Instance = S::Instance;
|
||||||
|
type InitError = S::InitError;
|
||||||
type Future = S::Future;
|
type Future = S::Future;
|
||||||
|
|
||||||
fn new_service(&self) -> Self::Future {
|
fn new_service(&self) -> Self::Future {
|
||||||
|
@ -212,6 +216,7 @@ impl<S: NewService + ?Sized> NewService for Rc<S> {
|
||||||
type Response = S::Response;
|
type Response = S::Response;
|
||||||
type Error = S::Error;
|
type Error = S::Error;
|
||||||
type Instance = S::Instance;
|
type Instance = S::Instance;
|
||||||
|
type InitError = S::InitError;
|
||||||
type Future = S::Future;
|
type Future = S::Future;
|
||||||
|
|
||||||
fn new_service(&self) -> Self::Future {
|
fn new_service(&self) -> Self::Future {
|
||||||
|
|
Loading…
Reference in New Issue