1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-09-02 17:46:38 +02:00

http server accepts factory of HttpHandlers

This commit is contained in:
Nikolay Kim
2017-12-12 07:40:36 -08:00
parent b9da09ddf0
commit e9aa67b75d
9 changed files with 34 additions and 31 deletions

View File

@@ -95,10 +95,11 @@ impl<T: 'static, A: 'static, H: 'static> Actor for HttpServer<T, A, H> {
impl<T, A, H> HttpServer<T, A, H> where H: HttpHandler
{
/// Create new http server with vec of http handlers
pub fn new<V, U: IntoIterator<Item=V>>(handler: U) -> Self
where V: IntoHttpHandler<Handler=H>
pub fn new<V, F, U: IntoIterator<Item=V>>(factory: F) -> Self
where F: Fn() -> U + Send,
V: IntoHttpHandler<Handler=H>
{
let apps: Vec<_> = handler.into_iter().map(|h| h.into_handler()).collect();
let apps: Vec<_> = factory().into_iter().map(|h| h.into_handler()).collect();
HttpServer{ h: Rc::new(apps),
io: PhantomData,