1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2025-04-25 02:54:06 +00:00

Fix formatting.

This commit is contained in:
anthonyjchriste 2019-06-24 09:16:06 -10:00
parent ee9fe60ccb
commit 70ffab8368

View file

@ -27,9 +27,9 @@ use futures::{Async, Future, Poll, Stream};
/// Do websocket handshake and start ws actor. /// Do websocket handshake and start ws actor.
pub fn start<A, T>(actor: A, req: &HttpRequest, stream: T) -> Result<HttpResponse, Error> pub fn start<A, T>(actor: A, req: &HttpRequest, stream: T) -> Result<HttpResponse, Error>
where where
A: Actor<Context = WebsocketContext<A>> + StreamHandler<Message, ProtocolError>, A: Actor<Context = WebsocketContext<A>> + StreamHandler<Message, ProtocolError>,
T: Stream<Item = Bytes, Error = PayloadError> + 'static, T: Stream<Item = Bytes, Error = PayloadError> + 'static,
{ {
let mut res = handshake(req)?; let mut res = handshake(req)?;
Ok(res.streaming(WebsocketContext::create(actor, stream))) Ok(res.streaming(WebsocketContext::create(actor, stream)))
@ -101,16 +101,16 @@ pub fn handshake(req: &HttpRequest) -> Result<HttpResponseBuilder, HandshakeErro
/// Execution context for `WebSockets` actors /// Execution context for `WebSockets` actors
pub struct WebsocketContext<A> pub struct WebsocketContext<A>
where where
A: Actor<Context = WebsocketContext<A>>, A: Actor<Context = WebsocketContext<A>>,
{ {
inner: ContextParts<A>, inner: ContextParts<A>,
messages: VecDeque<Option<Message>>, messages: VecDeque<Option<Message>>,
} }
impl<A> ActorContext for WebsocketContext<A> impl<A> ActorContext for WebsocketContext<A>
where where
A: Actor<Context = Self>, A: Actor<Context = Self>,
{ {
fn stop(&mut self) { fn stop(&mut self) {
self.inner.stop(); self.inner.stop();
@ -126,8 +126,8 @@ impl<A> ActorContext for WebsocketContext<A>
} }
impl<A> AsyncContext<A> for WebsocketContext<A> impl<A> AsyncContext<A> for WebsocketContext<A>
where where
A: Actor<Context = Self>, A: Actor<Context = Self>,
{ {
fn spawn<F>(&mut self, fut: F) -> SpawnHandle fn spawn<F>(&mut self, fut: F) -> SpawnHandle
where where
@ -137,8 +137,8 @@ impl<A> AsyncContext<A> for WebsocketContext<A>
} }
fn wait<F>(&mut self, fut: F) fn wait<F>(&mut self, fut: F)
where where
F: ActorFuture<Item = (), Error = (), Actor = A> + 'static, F: ActorFuture<Item = (), Error = (), Actor = A> + 'static,
{ {
self.inner.wait(fut) self.inner.wait(fut)
} }
@ -162,15 +162,15 @@ impl<A> AsyncContext<A> for WebsocketContext<A>
} }
impl<A> WebsocketContext<A> impl<A> WebsocketContext<A>
where where
A: Actor<Context = Self>, A: Actor<Context = Self>,
{ {
#[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 create<S>(actor: A, stream: S) -> impl Stream<Item = Bytes, Error = Error> pub fn create<S>(actor: A, stream: S) -> impl Stream<Item = Bytes, Error = Error>
where where
A: StreamHandler<Message, ProtocolError>, A: StreamHandler<Message, ProtocolError>,
S: Stream<Item = Bytes, Error = PayloadError> + 'static, S: Stream<Item = Bytes, Error = PayloadError> + 'static,
{ {
let mb = Mailbox::default(); let mb = Mailbox::default();
let mut ctx = WebsocketContext { let mut ctx = WebsocketContext {
@ -204,10 +204,10 @@ impl<A> WebsocketContext<A>
stream: S, stream: S,
f: F, f: F,
) -> impl Stream<Item = Bytes, Error = Error> ) -> impl Stream<Item = Bytes, Error = Error>
where where
F: FnOnce(&mut Self) -> A + 'static, F: FnOnce(&mut Self) -> A + 'static,
A: StreamHandler<Message, ProtocolError>, A: StreamHandler<Message, ProtocolError>,
S: Stream<Item = Bytes, Error = PayloadError> + 'static, S: Stream<Item = Bytes, Error = PayloadError> + 'static,
{ {
let mb = Mailbox::default(); let mb = Mailbox::default();
let mut ctx = WebsocketContext { let mut ctx = WebsocketContext {
@ -223,8 +223,8 @@ impl<A> WebsocketContext<A>
} }
impl<A> WebsocketContext<A> impl<A> WebsocketContext<A>
where where
A: Actor<Context = Self>, A: Actor<Context = Self>,
{ {
/// Write payload /// Write payload
/// ///
@ -283,8 +283,8 @@ impl<A> WebsocketContext<A>
} }
impl<A> AsyncContextParts<A> for WebsocketContext<A> impl<A> AsyncContextParts<A> for WebsocketContext<A>
where where
A: Actor<Context = Self>, A: Actor<Context = Self>,
{ {
fn parts(&mut self) -> &mut ContextParts<A> { fn parts(&mut self) -> &mut ContextParts<A> {
&mut self.inner &mut self.inner
@ -302,8 +302,8 @@ struct WebsocketContextFut<A>
} }
impl<A> WebsocketContextFut<A> impl<A> WebsocketContextFut<A>
where where
A: Actor<Context = WebsocketContext<A>>, A: Actor<Context = WebsocketContext<A>>,
{ {
fn new(ctx: WebsocketContext<A>, act: A, mailbox: Mailbox<A>, codec: Codec) -> Self { fn new(ctx: WebsocketContext<A>, act: A, mailbox: Mailbox<A>, codec: Codec) -> Self {
let fut = ContextFut::new(ctx, act, mailbox); let fut = ContextFut::new(ctx, act, mailbox);
@ -317,8 +317,8 @@ impl<A> WebsocketContextFut<A>
} }
impl<A> Stream for WebsocketContextFut<A> impl<A> Stream for WebsocketContextFut<A>
where where
A: Actor<Context = WebsocketContext<A>>, A: Actor<Context = WebsocketContext<A>>,
{ {
type Item = Bytes; type Item = Bytes;
type Error = Error; type Error = Error;
@ -349,10 +349,10 @@ impl<A> Stream for WebsocketContextFut<A>
} }
impl<A, M> ToEnvelope<A, M> for WebsocketContext<A> impl<A, M> ToEnvelope<A, M> for WebsocketContext<A>
where where
A: Actor<Context = WebsocketContext<A>> + Handler<M>, A: Actor<Context = WebsocketContext<A>> + Handler<M>,
M: ActixMessage + Send + 'static, M: ActixMessage + Send + 'static,
M::Result: Send, M::Result: Send,
{ {
fn pack(msg: M, tx: Option<Sender<M::Result>>) -> Envelope<A> { fn pack(msg: M, tx: Option<Sender<M::Result>>) -> Envelope<A> {
Envelope::new(msg, tx) Envelope::new(msg, tx)
@ -367,8 +367,8 @@ struct WsStream<S> {
} }
impl<S> WsStream<S> impl<S> WsStream<S>
where where
S: Stream<Item = Bytes, Error = PayloadError>, S: Stream<Item = Bytes, Error = PayloadError>,
{ {
fn new(stream: S, codec: Codec) -> Self { fn new(stream: S, codec: Codec) -> Self {
Self { Self {
@ -381,8 +381,8 @@ impl<S> WsStream<S>
} }
impl<S> Stream for WsStream<S> impl<S> Stream for WsStream<S>
where where
S: Stream<Item = Bytes, Error = PayloadError>, S: Stream<Item = Bytes, Error = PayloadError>,
{ {
type Item = Message; type Item = Message;
type Error = ProtocolError; type Error = ProtocolError;