1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-31 00:50:20 +02:00

refactor service registration process; unify services and resources

This commit is contained in:
Nikolay Kim
2019-03-06 15:47:15 -08:00
parent 5cde4dc479
commit fe22e83144
18 changed files with 845 additions and 779 deletions

View File

@@ -1,6 +1,7 @@
use std::borrow::Cow;
use std::cell::{Ref, RefMut};
use std::fmt;
use std::marker::PhantomData;
use std::rc::Rc;
use actix_http::body::{Body, MessageBody, ResponseBody};
@@ -12,8 +13,42 @@ use actix_http::{
use actix_router::{Path, Resource, Url};
use futures::future::{ok, FutureResult, IntoFuture};
use crate::config::AppConfig;
use crate::request::HttpRequest;
pub trait HttpServiceFactory<P> {
fn register(self, config: &mut AppConfig<P>);
}
pub(crate) trait ServiceFactory<P> {
fn register(&mut self, config: &mut AppConfig<P>);
}
pub(crate) struct ServiceFactoryWrapper<T, P> {
factory: Option<T>,
_t: PhantomData<P>,
}
impl<T, P> ServiceFactoryWrapper<T, P> {
pub fn new(factory: T) -> Self {
Self {
factory: Some(factory),
_t: PhantomData,
}
}
}
impl<T, P> ServiceFactory<P> for ServiceFactoryWrapper<T, P>
where
T: HttpServiceFactory<P>,
{
fn register(&mut self, config: &mut AppConfig<P>) {
if let Some(item) = self.factory.take() {
item.register(config)
}
}
}
pub struct ServiceRequest<P = PayloadStream> {
req: HttpRequest,
payload: Payload<P>,