From 14c605fae2e6cf7e51c0b77185d04777d34b5476 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Thu, 20 Jun 2024 02:10:19 +0100 Subject: [PATCH] docs: indicative mood --- actix-ws/src/fut.rs | 8 ++++---- actix-ws/src/session.rs | 32 ++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/actix-ws/src/fut.rs b/actix-ws/src/fut.rs index 786240485..d62b9b232 100644 --- a/actix-ws/src/fut.rs +++ b/actix-ws/src/fut.rs @@ -1,7 +1,7 @@ use std::{ collections::VecDeque, future::poll_fn, - io, + io, mem, pin::Pin, task::{Context, Poll}, }; @@ -102,13 +102,13 @@ impl Stream for StreamingBody { } while let Some(msg) = this.messages.pop_front() { - if let Err(e) = this.codec.encode(msg, &mut this.buf) { - return Poll::Ready(Some(Err(e.into()))); + if let Err(err) = this.codec.encode(msg, &mut this.buf) { + return Poll::Ready(Some(Err(err.into()))); } } if !this.buf.is_empty() { - return Poll::Ready(Some(Ok(std::mem::take(&mut this.buf).freeze()))); + return Poll::Ready(Some(Ok(mem::take(&mut this.buf).freeze()))); } Poll::Pending diff --git a/actix-ws/src/session.rs b/actix-ws/src/session.rs index 4855b4760..ad210809e 100644 --- a/actix-ws/src/session.rs +++ b/actix-ws/src/session.rs @@ -1,6 +1,9 @@ -use std::sync::{ - atomic::{AtomicBool, Ordering}, - Arc, +use std::{ + fmt, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, + }, }; use actix_http::ws::{CloseReason, Item, Message}; @@ -10,7 +13,7 @@ use tokio::sync::mpsc::Sender; /// A handle into the websocket session. /// -/// This type can be used to send messages into the websocket. +/// This type can be used to send messages into the WebSocket. #[derive(Clone)] pub struct Session { inner: Option>, @@ -21,9 +24,9 @@ pub struct Session { #[derive(Debug)] pub struct Closed; -impl std::fmt::Display for Closed { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "Session is closed") +impl fmt::Display for Closed { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("Session is closed") } } @@ -43,7 +46,7 @@ impl Session { } } - /// Send text into the websocket + /// Sends text into the WebSocket. /// /// ```no_run /// # use actix_ws::Session; @@ -65,7 +68,7 @@ impl Session { } } - /// Send raw bytes into the websocket + /// Sends raw bytes into the WebSocket. /// /// ```no_run /// # use actix_ws::Session; @@ -87,7 +90,7 @@ impl Session { } } - /// Ping the client + /// Pings the client. /// /// For many applications, it will be important to send regular pings to keep track of if the /// client has disconnected @@ -112,7 +115,7 @@ impl Session { } } - /// Pong the client + /// Pongs the client. /// /// ```no_run /// # use actix_ws::{Message, Session}; @@ -136,7 +139,7 @@ impl Session { } } - /// Manually control sending continuations + /// Manually controls sending continuations. /// /// Be wary of this method. Continuations represent multiple frames that, when combined, are /// presented as a single message. They are useful when the entire contents of a message are @@ -168,9 +171,9 @@ impl Session { } } - /// Send a close message, and consume the session + /// Sends a close message, and consumes the session. /// - /// All clones will return `Err(Closed)` if used after this call + /// All clones will return `Err(Closed)` if used after this call. /// /// ```no_run /// # use actix_ws::{Closed, Session}; @@ -180,6 +183,7 @@ impl Session { /// ``` pub async fn close(mut self, reason: Option) -> Result<(), Closed> { self.pre_check(); + if let Some(inner) = self.inner.take() { self.closed.store(true, Ordering::Relaxed); inner.send(Message::Close(reason)).await.map_err(|_| Closed)