1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-24 00:21:08 +01:00

remove Context::actor() method

This commit is contained in:
Nikolay Kim 2018-06-17 03:10:44 +06:00
parent e4443226f6
commit 33050f55a3
2 changed files with 32 additions and 22 deletions

View File

@ -104,24 +104,29 @@ where
#[inline]
/// Create a new HTTP Context from a request and an actor
pub fn new(req: HttpRequest<S>, actor: A) -> HttpContext<A, S> {
HttpContext::from_request(req).actor(actor)
}
/// Create a new HTTP Context from a request
pub fn from_request(req: HttpRequest<S>) -> HttpContext<A, S> {
HttpContext {
inner: ContextImpl::new(None),
inner: ContextImpl::new(Some(actor)),
stream: None,
request: req,
disconnected: false,
}
}
#[inline]
/// Set the actor of this context
pub fn actor(mut self, actor: A) -> HttpContext<A, S> {
self.inner.set_actor(actor);
self
/// Create a new HTTP Context
pub fn with_factory<F>(req: HttpRequest<S>, f: F) -> HttpContext<A, S>
where
F: FnOnce(&mut Self) -> A + 'static,
{
let mut ctx = HttpContext {
inner: ContextImpl::new(None),
stream: None,
request: req,
disconnected: false,
};
let act = f(&mut ctx);
ctx.inner.set_actor(act);
ctx
}
}

View File

@ -88,24 +88,29 @@ where
#[inline]
/// Create a new Websocket context from a request and an actor
pub fn new(req: HttpRequest<S>, actor: A) -> WebsocketContext<A, S> {
WebsocketContext::from_request(req).actor(actor)
}
/// Create a new Websocket context from a request
pub fn from_request(req: HttpRequest<S>) -> WebsocketContext<A, S> {
WebsocketContext {
inner: ContextImpl::new(None),
inner: ContextImpl::new(Some(actor)),
stream: None,
request: req,
disconnected: false,
}
}
#[inline]
/// Set actor for this execution context
pub fn actor(mut self, actor: A) -> WebsocketContext<A, S> {
self.inner.set_actor(actor);
self
/// Create a new Websocket context
pub fn with_factory<F>(req: HttpRequest<S>, f: F) -> Self
where
F: FnOnce(&mut Self) -> A + 'static,
{
let mut ctx = WebsocketContext {
inner: ContextImpl::new(None),
stream: None,
request: req,
disconnected: false,
};
let act = f(&mut ctx);
ctx.inner.set_actor(act);
ctx
}
}