1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-06-29 01:50:35 +02:00

add basic example

This commit is contained in:
Nikolay Kim
2018-08-20 21:34:47 -07:00
parent 36ed2307ce
commit ac70f06c4f
3 changed files with 135 additions and 20 deletions

View File

@ -164,7 +164,8 @@ impl Server {
N::Error: fmt::Display,
{
let token = Token(self.services.len());
self.services.push(ServerNewService::create(srv.into()));
self.services
.push(ServerNewService::create(srv.into_new_service()));
self.sockets.push((token, lst));
self
}

View File

@ -74,7 +74,7 @@ where
T: NewService,
{
/// Create service
fn into(self) -> T;
fn into_new_service(self) -> T;
}
impl<T> IntoService<T> for T
@ -90,7 +90,7 @@ impl<T> IntoNewService<T> for T
where
T: NewService,
{
fn into(self) -> T {
fn into_new_service(self) -> T {
self
}
}
@ -198,7 +198,7 @@ where
F: Fn(Req) -> Fut + Clone + 'static,
Fut: IntoFuture<Item = Resp, Error = Err>,
{
fn into(self) -> FnNewService<F, Req, Resp, Err, Fut> {
fn into_new_service(self) -> FnNewService<F, Req, Resp, Err, Fut> {
FnNewService::new(self)
}
}
@ -334,7 +334,9 @@ where
Err1: 'static,
Err2: 'static,
{
fn into(self) -> FnStateNewService<S, F1, F2, Req, Resp, Err1, Err2, Fut1, Fut2> {
fn into_new_service(
self,
) -> FnStateNewService<S, F1, F2, Req, Resp, Err1, Err2, Fut1, Fut2> {
FnStateNewService::new(self.0, self.1)
}
}
@ -456,7 +458,10 @@ where
{
/// Create new `AndThen` combinator
pub fn new<F: IntoNewService<B>>(a: A, f: F) -> Self {
Self { a, b: f.into() }
Self {
a,
b: f.into_new_service(),
}
}
}
@ -640,6 +645,20 @@ where
}
}
impl<A, F, E> Clone for MapErrNewService<A, F, E>
where
A: NewService + Clone,
F: Fn(A::InitError) -> E + Clone,
{
fn clone(&self) -> Self {
Self {
a: self.a.clone(),
f: self.f.clone(),
e: marker::PhantomData,
}
}
}
impl<A, F, E> NewService for MapErrNewService<A, F, E>
where
A: NewService + Clone,
@ -658,20 +677,6 @@ where
}
}
impl<A, F, E> Clone for MapErrNewService<A, F, E>
where
A: NewService + Clone,
F: Fn(A::Error) -> E + Clone,
{
fn clone(&self) -> Self {
Self {
a: self.a.clone(),
f: self.f.clone(),
e: marker::PhantomData,
}
}
}
pub struct MapErrNewServiceFuture<A, F, E>
where
A: NewService,
@ -730,6 +735,20 @@ where
}
}
impl<A, F, E> Clone for MapInitErr<A, F, E>
where
A: NewService + Clone,
F: Fn(A::InitError) -> E + Clone,
{
fn clone(&self) -> Self {
Self {
a: self.a.clone(),
f: self.f.clone(),
e: marker::PhantomData,
}
}
}
impl<A, F, E> NewService for MapInitErr<A, F, E>
where
A: NewService,