mirror of
https://github.com/fafhrd91/actix-net
synced 2025-06-26 22:07:42 +02:00
update tests
This commit is contained in:
@ -3,7 +3,7 @@ use std::marker::PhantomData;
|
||||
use futures::future::{ok, FutureResult};
|
||||
use futures::{Async, IntoFuture, Poll};
|
||||
|
||||
use super::{IntoService, NewService, Service};
|
||||
use super::{IntoNewService, IntoService, NewService, Service};
|
||||
|
||||
pub struct FnService<F, Req, Out>
|
||||
where
|
||||
@ -112,3 +112,64 @@ where
|
||||
Self::new(self.f.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<F, R, S, E> IntoNewService<FnNewServiceNoConfig<F, R, S, E>, ()> for F
|
||||
where
|
||||
F: Fn() -> R + Clone,
|
||||
R: IntoFuture<Item = S, Error = E>,
|
||||
S: Service,
|
||||
{
|
||||
fn into_new_service(self) -> FnNewServiceNoConfig<F, R, S, E> {
|
||||
FnNewServiceNoConfig::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FnNewServiceNoConfig<F, R, S, E>
|
||||
where
|
||||
F: Fn() -> R + Clone,
|
||||
R: IntoFuture<Item = S, Error = E>,
|
||||
S: Service,
|
||||
{
|
||||
f: F,
|
||||
}
|
||||
|
||||
impl<F, R, S, E> FnNewServiceNoConfig<F, R, S, E>
|
||||
where
|
||||
F: Fn() -> R + Clone,
|
||||
R: IntoFuture<Item = S, Error = E>,
|
||||
S: Service,
|
||||
{
|
||||
pub fn new(f: F) -> Self {
|
||||
FnNewServiceNoConfig { f }
|
||||
}
|
||||
}
|
||||
|
||||
impl<F, R, S, E> NewService<()> for FnNewServiceNoConfig<F, R, S, E>
|
||||
where
|
||||
F: Fn() -> R + Clone,
|
||||
R: IntoFuture<Item = S, Error = E>,
|
||||
S: Service,
|
||||
{
|
||||
type Request = S::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.f)().into_future()
|
||||
}
|
||||
}
|
||||
|
||||
impl<F, R, S, E> Clone for FnNewServiceNoConfig<F, R, S, E>
|
||||
where
|
||||
F: Fn() -> R + Clone,
|
||||
R: IntoFuture<Item = S, Error = E>,
|
||||
S: Service,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self::new(self.f.clone())
|
||||
}
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_new_service() {
|
||||
let blank = || Ok::<_, ()>(Srv);
|
||||
let blank = |_: &()| Ok::<_, ()>(Srv);
|
||||
let new_srv = blank.into_new_service().map_err(|_| "error");
|
||||
if let Async::Ready(mut srv) = new_srv.new_service(&()).poll().unwrap() {
|
||||
let res = srv.call(()).poll();
|
||||
|
Reference in New Issue
Block a user