1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-21 15:46:48 +00:00

better naming

This commit is contained in:
Nikolay Kim 2019-03-03 08:24:09 -08:00
parent 015364edf8
commit b81ae899f6
2 changed files with 32 additions and 29 deletions

View file

@ -35,7 +35,6 @@ before_script:
script: script:
- cargo clean - cargo clean
- cargo check
- cargo test -- --nocapture - cargo test -- --nocapture
# Upload docs # Upload docs

View file

@ -188,13 +188,13 @@ where
> >
where where
M: NewTransform< M: NewTransform<
AppService<P>, AppRouting<P>,
Request = ServiceRequest<P>, Request = ServiceRequest<P>,
Response = ServiceResponse<B>, Response = ServiceResponse<B>,
Error = (), Error = (),
InitError = (), InitError = (),
>, >,
F: IntoNewTransform<M, AppService<P>>, F: IntoNewTransform<M, AppRouting<P>>,
{ {
let fref = Rc::new(RefCell::new(None)); let fref = Rc::new(RefCell::new(None));
let endpoint = ApplyNewService::new(mw, AppEntry::new(fref.clone())); let endpoint = ApplyNewService::new(mw, AppEntry::new(fref.clone()));
@ -253,7 +253,7 @@ pub struct AppRouter<C, P, B, T> {
default: Option<Rc<HttpNewService<P>>>, default: Option<Rc<HttpNewService<P>>>,
defaults: Vec<Rc<RefCell<Option<Rc<HttpNewService<P>>>>>>, defaults: Vec<Rc<RefCell<Option<Rc<HttpNewService<P>>>>>>,
endpoint: T, endpoint: T,
factory_ref: Rc<RefCell<Option<AppFactory<P>>>>, factory_ref: Rc<RefCell<Option<AppRoutingFactory<P>>>>,
extensions: Extensions, extensions: Extensions,
state: Vec<Box<StateFactory>>, state: Vec<Box<StateFactory>>,
_t: PhantomData<(P, B)>, _t: PhantomData<(P, B)>,
@ -465,7 +465,7 @@ where
} }
// set factory // set factory
*self.factory_ref.borrow_mut() = Some(AppFactory { *self.factory_ref.borrow_mut() = Some(AppRoutingFactory {
services: Rc::new(self.services), services: Rc::new(self.services),
}); });
@ -478,25 +478,25 @@ where
} }
} }
pub struct AppFactory<P> { pub struct AppRoutingFactory<P> {
services: Rc<Vec<(ResourceDef, HttpNewService<P>)>>, services: Rc<Vec<(ResourceDef, HttpNewService<P>)>>,
} }
impl<P: 'static> NewService for AppFactory<P> { impl<P: 'static> NewService for AppRoutingFactory<P> {
type Request = ServiceRequest<P>; type Request = ServiceRequest<P>;
type Response = ServiceResponse; type Response = ServiceResponse;
type Error = (); type Error = ();
type InitError = (); type InitError = ();
type Service = AppService<P>; type Service = AppRouting<P>;
type Future = CreateAppService<P>; type Future = AppRoutingFactoryResponse<P>;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: &()) -> Self::Future {
CreateAppService { AppRoutingFactoryResponse {
fut: self fut: self
.services .services
.iter() .iter()
.map(|(path, service)| { .map(|(path, service)| {
CreateAppServiceItem::Future( CreateAppRoutingItem::Future(
Some(path.clone()), Some(path.clone()),
service.new_service(&()), service.new_service(&()),
) )
@ -510,17 +510,17 @@ type HttpServiceFut<P> = Box<Future<Item = HttpService<P>, Error = ()>>;
/// Create app service /// Create app service
#[doc(hidden)] #[doc(hidden)]
pub struct CreateAppService<P> { pub struct AppRoutingFactoryResponse<P> {
fut: Vec<CreateAppServiceItem<P>>, fut: Vec<CreateAppRoutingItem<P>>,
} }
enum CreateAppServiceItem<P> { enum CreateAppRoutingItem<P> {
Future(Option<ResourceDef>, HttpServiceFut<P>), Future(Option<ResourceDef>, HttpServiceFut<P>),
Service(ResourceDef, HttpService<P>), Service(ResourceDef, HttpService<P>),
} }
impl<P> Future for CreateAppService<P> { impl<P> Future for AppRoutingFactoryResponse<P> {
type Item = AppService<P>; type Item = AppRouting<P>;
type Error = (); type Error = ();
fn poll(&mut self) -> Poll<Self::Item, Self::Error> { fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
@ -529,7 +529,7 @@ impl<P> Future for CreateAppService<P> {
// poll http services // poll http services
for item in &mut self.fut { for item in &mut self.fut {
let res = match item { let res = match item {
CreateAppServiceItem::Future(ref mut path, ref mut fut) => { CreateAppRoutingItem::Future(ref mut path, ref mut fut) => {
match fut.poll()? { match fut.poll()? {
Async::Ready(service) => Some((path.take().unwrap(), service)), Async::Ready(service) => Some((path.take().unwrap(), service)),
Async::NotReady => { Async::NotReady => {
@ -538,11 +538,11 @@ impl<P> Future for CreateAppService<P> {
} }
} }
} }
CreateAppServiceItem::Service(_, _) => continue, CreateAppRoutingItem::Service(_, _) => continue,
}; };
if let Some((path, service)) = res { if let Some((path, service)) = res {
*item = CreateAppServiceItem::Service(path, service); *item = CreateAppRoutingItem::Service(path, service);
} }
} }
@ -552,14 +552,14 @@ impl<P> Future for CreateAppService<P> {
.drain(..) .drain(..)
.fold(Router::build(), |mut router, item| { .fold(Router::build(), |mut router, item| {
match item { match item {
CreateAppServiceItem::Service(path, service) => { CreateAppRoutingItem::Service(path, service) => {
router.rdef(path, service) router.rdef(path, service)
} }
CreateAppServiceItem::Future(_, _) => unreachable!(), CreateAppRoutingItem::Future(_, _) => unreachable!(),
} }
router router
}); });
Ok(Async::Ready(AppService { Ok(Async::Ready(AppRouting {
router: router.finish(), router: router.finish(),
ready: None, ready: None,
})) }))
@ -569,12 +569,12 @@ impl<P> Future for CreateAppService<P> {
} }
} }
pub struct AppService<P> { pub struct AppRouting<P> {
router: Router<HttpService<P>>, router: Router<HttpService<P>>,
ready: Option<(ServiceRequest<P>, ResourceInfo)>, ready: Option<(ServiceRequest<P>, ResourceInfo)>,
} }
impl<P> Service for AppService<P> { impl<P> Service for AppRouting<P> {
type Request = ServiceRequest<P>; type Request = ServiceRequest<P>;
type Response = ServiceResponse; type Response = ServiceResponse;
type Error = (); type Error = ();
@ -599,12 +599,13 @@ impl<P> Service for AppService<P> {
} }
#[doc(hidden)] #[doc(hidden)]
/// Wrapper service for routing
pub struct AppEntry<P> { pub struct AppEntry<P> {
factory: Rc<RefCell<Option<AppFactory<P>>>>, factory: Rc<RefCell<Option<AppRoutingFactory<P>>>>,
} }
impl<P> AppEntry<P> { impl<P> AppEntry<P> {
fn new(factory: Rc<RefCell<Option<AppFactory<P>>>>) -> Self { fn new(factory: Rc<RefCell<Option<AppRoutingFactory<P>>>>) -> Self {
AppEntry { factory } AppEntry { factory }
} }
} }
@ -614,8 +615,8 @@ impl<P: 'static> NewService for AppEntry<P> {
type Response = ServiceResponse; type Response = ServiceResponse;
type Error = (); type Error = ();
type InitError = (); type InitError = ();
type Service = AppService<P>; type Service = AppRouting<P>;
type Future = CreateAppService<P>; type Future = AppRoutingFactoryResponse<P>;
fn new_service(&self, _: &()) -> Self::Future { fn new_service(&self, _: &()) -> Self::Future {
self.factory.borrow_mut().as_mut().unwrap().new_service(&()) self.factory.borrow_mut().as_mut().unwrap().new_service(&())
@ -644,16 +645,19 @@ impl Service for AppChain {
type Error = (); type Error = ();
type Future = FutureResult<Self::Response, Self::Error>; type Future = FutureResult<Self::Response, Self::Error>;
#[inline]
fn poll_ready(&mut self) -> Poll<(), Self::Error> { fn poll_ready(&mut self) -> Poll<(), Self::Error> {
Ok(Async::Ready(())) Ok(Async::Ready(()))
} }
#[inline]
fn call(&mut self, req: Self::Request) -> Self::Future { fn call(&mut self, req: Self::Request) -> Self::Future {
ok(req) ok(req)
} }
} }
/// Service factory to convert `Request` to a `ServiceRequest<S>` /// Service factory to convert `Request` to a `ServiceRequest<S>`.
/// It also executes state factories.
pub struct AppInit<C, P> pub struct AppInit<C, P>
where where
C: NewService<Request = ServiceRequest<PayloadStream>, Response = ServiceRequest<P>>, C: NewService<Request = ServiceRequest<PayloadStream>, Response = ServiceRequest<P>>,