Skip to content

Commit

Permalink
rename ServiceFactoryExt to BuildServiceExt. (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
fakeshadow authored Apr 28, 2022
1 parent fda87e8 commit 72345d2
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion examples/multi-services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use xitca_http::{
util::middleware::{Logger, TcpConfig},
HttpServiceBuilder, Request, ResponseBody,
};
use xitca_service::{fn_service, ServiceFactoryExt};
use xitca_service::{fn_service, BuildServiceExt};

#[tokio::main(flavor = "current_thread")]
async fn main() -> io::Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion http/src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{error, future::Future, marker::PhantomData};

use xitca_io::net::{Stream as ServerStream, TcpStream};
use xitca_service::{BuildService, EnclosedFactory, ServiceFactoryExt};
use xitca_service::{BuildService, BuildServiceExt, EnclosedFactory};

use super::{
body::RequestBody,
Expand Down
2 changes: 1 addition & 1 deletion http/src/util/middleware/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ where
mod test {
use super::*;

use xitca_service::{fn_service, BuildService, ServiceFactoryExt};
use xitca_service::{fn_service, BuildService, BuildServiceExt};

use crate::request::Request;

Expand Down
2 changes: 1 addition & 1 deletion http/src/util/service/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ pub mod object {
mod test {
use std::convert::Infallible;

use xitca_service::{fn_service, ServiceFactoryExt};
use xitca_service::{fn_service, BuildServiceExt};

use crate::{
http::Response,
Expand Down
2 changes: 1 addition & 1 deletion http/src/util/service/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ mod test {
future::{ready, Ready},
};

use xitca_service::{Service, ServiceFactoryExt};
use xitca_service::{BuildServiceExt, Service};

use crate::http::{Response, StatusCode};
use crate::util::service::{route::get, Router};
Expand Down
2 changes: 1 addition & 1 deletion http/src/util/service/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
};

use xitca_service::{
pipeline::PipelineE, ready::ReadyService, BuildService, MapErrorServiceFactory, Service, ServiceFactoryExt,
pipeline::PipelineE, ready::ReadyService, BuildService, BuildServiceExt, MapErrorServiceFactory, Service,
};

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion http/src/util/service/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ mod test {

use std::convert::Infallible;

use xitca_service::{fn_service, Service, ServiceFactoryExt};
use xitca_service::{fn_service, BuildServiceExt, Service};

use crate::{
http::{self, Response},
Expand Down
6 changes: 3 additions & 3 deletions service/src/build/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ use crate::BoxFuture;

use super::BuildService;

pub struct BoxedServiceFactory<SF> {
pub struct Boxed<SF> {
factory: SF,
}

impl<SF> BoxedServiceFactory<SF> {
impl<SF> Boxed<SF> {
pub(super) fn new(factory: SF) -> Self {
Self { factory }
}
}

impl<SF, Arg> BuildService<Arg> for BoxedServiceFactory<SF>
impl<SF, Arg> BuildService<Arg> for Boxed<SF>
where
SF: BuildService<Arg>,
SF::Future: 'static,
Expand Down
10 changes: 5 additions & 5 deletions service/src/build/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::{
pipeline::{marker, PipelineT},
};

use super::{boxed::BoxedServiceFactory, BuildService};
use super::{boxed::Boxed, BuildService};

pub trait ServiceFactoryExt<Arg>: BuildService<Arg> {
pub trait BuildServiceExt<Arg>: BuildService<Arg> {
fn map<F, Res, ResMap>(self, mapper: F) -> PipelineT<Self, F, marker::Map>
where
F: Fn(Res) -> ResMap + Clone,
Expand All @@ -26,11 +26,11 @@ pub trait ServiceFactoryExt<Arg>: BuildService<Arg> {
/// Box `<Self as ServiceFactory<_>>::Future` to reduce it's stack size.
///
/// *. This combinator does not box `Self` or `Self::Service`.
fn boxed_future(self) -> BoxedServiceFactory<Self>
fn boxed_future(self) -> Boxed<Self>
where
Self: Sized,
{
BoxedServiceFactory::new(self)
Boxed::new(self)
}

/// Chain another service factory who's service takes `Self`'s `Service::Response` output as
Expand Down Expand Up @@ -73,7 +73,7 @@ pub trait ServiceFactoryExt<Arg>: BuildService<Arg> {
}
}

impl<F, Arg> ServiceFactoryExt<Arg> for F where F: BuildService<Arg> {}
impl<F, Arg> BuildServiceExt<Arg> for F where F: BuildService<Arg> {}

#[cfg(test)]
mod test {
Expand Down
2 changes: 1 addition & 1 deletion service/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod map;
mod map_err;

pub use self::{
ext::ServiceFactoryExt,
ext::BuildServiceExt,
function::{fn_build, fn_service},
};

Expand Down
2 changes: 1 addition & 1 deletion service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub mod ready;

pub use self::{
async_closure::AsyncClosure,
build::{fn_build, fn_service, BuildService, ServiceFactoryExt},
build::{fn_build, fn_service, BuildService, BuildServiceExt},
pipeline::{EnclosedFactory, EnclosedFnFactory, MapErrorServiceFactory},
service::Service,
};
Expand Down
2 changes: 1 addition & 1 deletion service/src/middleware/cloneable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl<S> BuildService<S> for Cloneable {
mod test {
use super::*;

use crate::{fn_service, BuildService, Service, ServiceFactoryExt};
use crate::{fn_service, BuildService, BuildServiceExt, Service};

#[tokio::test]
async fn cloneable() {
Expand Down
2 changes: 1 addition & 1 deletion service/src/middleware/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Useful Service types that can be used with [crate::ServiceFactoryExt::enclosed] method.
//! Useful Service types that can be used with [crate::BuildServiceExt::enclosed] method.
mod cloneable;

Expand Down
5 changes: 2 additions & 3 deletions service/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ pub mod helpers {
type Error = Inner::Error;

fn new_service(&self, arg: Arg) -> BoxFuture<'static, Self::Service, Self::Error> {
let fut = BuildService::build(&self.0, arg);
Box::pin(fut)
Box::pin(BuildService::build(&self.0, arg))
}
}

Expand Down Expand Up @@ -139,7 +138,7 @@ pub mod helpers {
Req: 'f,
's: 'f,
{
Box::pin(async move { Service::call(&self.0, req).await })
Box::pin(Service::call(&self.0, req))
}
}
}
2 changes: 1 addition & 1 deletion test/tests/macro.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(generic_associated_types, type_alias_impl_trait)]

use xitca_service::{ready::ReadyService, BuildService, Service, ServiceFactoryExt};
use xitca_service::{ready::ReadyService, BuildService, BuildServiceExt, Service};

struct Test;

Expand Down
17 changes: 10 additions & 7 deletions web/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use xitca_http::{
Request, RequestBody,
};
use xitca_service::{
object::ObjectConstructor, ready::ReadyService, AsyncClosure, BuildService, EnclosedFactory, EnclosedFnFactory,
Service, ServiceFactoryExt,
object::ObjectConstructor, ready::ReadyService, AsyncClosure, BuildService, BuildServiceExt, EnclosedFactory,
EnclosedFnFactory, Service,
};

use crate::request::WebRequest;
Expand Down Expand Up @@ -77,10 +77,12 @@ impl<CF, C, SF> App<CF, Router<C, SF>> {
}
}

impl<CF, R> App<CF, R> {
impl<CF, R> App<CF, R>
where
R: BuildService,
{
pub fn enclosed<T>(self, transform: T) -> App<CF, EnclosedFactory<R, T>>
where
R: BuildService,
T: BuildService<R::Service> + Clone,
{
App {
Expand All @@ -91,7 +93,6 @@ impl<CF, R> App<CF, R> {

pub fn enclosed_fn<Req, T>(self, transform: T) -> App<CF, EnclosedFnFactory<R, T>>
where
R: BuildService,
T: for<'s> AsyncClosure<(&'s R::Service, Req)> + Clone,
{
App {
Expand All @@ -100,11 +101,13 @@ impl<CF, R> App<CF, R> {
}
}

pub fn finish<Req, Fut, C, CErr>(self) -> ContextBuilder<CF, C, MapRequest<R>>
pub fn finish<Fut, C, CErr>(self) -> ContextBuilder<CF, C, MapRequest<R>>
where
CF: Fn() -> Fut,
Fut: Future<Output = Result<C, CErr>>,
ContextBuilder<CF, C, MapRequest<R>>: BuildService<Req>,
C: 'static,
R: 'static,
R::Error: From<CErr>,
{
let App { ctx_factory, router } = self;

Expand Down
2 changes: 1 addition & 1 deletion web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub mod route {

pub mod dev {
pub use xitca_http::bytes;
pub use xitca_service::{fn_service, BuildService, Service, ServiceFactoryExt};
pub use xitca_service::{fn_service, BuildService, BuildServiceExt, Service};
}

pub use app::App;
Expand Down

0 comments on commit 72345d2

Please sign in to comment.