1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-24 08:22:59 +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] #[inline]
/// Create a new HTTP Context from a request and an actor /// Create a new HTTP Context from a request and an actor
pub fn new(req: HttpRequest<S>, actor: A) -> HttpContext<A, S> { 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 { HttpContext {
inner: ContextImpl::new(None), inner: ContextImpl::new(Some(actor)),
stream: None, stream: None,
request: req, request: req,
disconnected: false, disconnected: false,
} }
} }
#[inline] /// Create a new HTTP Context
/// Set the actor of this context pub fn with_factory<F>(req: HttpRequest<S>, f: F) -> HttpContext<A, S>
pub fn actor(mut self, actor: A) -> HttpContext<A, S> { where
self.inner.set_actor(actor); F: FnOnce(&mut Self) -> A + 'static,
self {
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] #[inline]
/// Create a new Websocket context from a request and an actor /// Create a new Websocket context from a request and an actor
pub fn new(req: HttpRequest<S>, actor: A) -> WebsocketContext<A, S> { 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 { WebsocketContext {
inner: ContextImpl::new(None), inner: ContextImpl::new(Some(actor)),
stream: None, stream: None,
request: req, request: req,
disconnected: false, disconnected: false,
} }
} }
#[inline] /// Create a new Websocket context
/// Set actor for this execution context pub fn with_factory<F>(req: HttpRequest<S>, f: F) -> Self
pub fn actor(mut self, actor: A) -> WebsocketContext<A, S> { where
self.inner.set_actor(actor); F: FnOnce(&mut Self) -> A + 'static,
self {
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
} }
} }