From 3a0212d4607ed47462e328a9ec84ac10f0208053 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 21 Sep 2017 16:50:28 -0700 Subject: [PATCH] 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. --- src/lib.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2be8b75..5035092 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,6 @@ extern crate futures; use futures::{Future, IntoFuture}; -use std::io; use std::rc::Rc; use std::sync::Arc; @@ -172,22 +171,26 @@ pub trait NewService { /// The `Service` value created by this factory type Instance: Service; + /// Errors produced while building a service. + type InitError; + /// The future of the `Service` instance. - type Future: Future; + type Future: Future; /// Create and return a new service value asynchronously. fn new_service(&self) -> Self::Future; } -impl NewService for F +impl NewService for F where F: Fn() -> R, - R: IntoFuture, + R: IntoFuture, 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 { @@ -200,6 +203,7 @@ impl NewService for Arc { 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 { @@ -212,6 +216,7 @@ impl NewService for Rc { 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 {