1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-27 09:12:57 +01:00

docs: indicative mood

This commit is contained in:
Rob Ede 2024-06-20 02:10:19 +01:00
parent d94c023bf9
commit 14c605fae2
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
2 changed files with 22 additions and 18 deletions

View File

@ -1,7 +1,7 @@
use std::{ use std::{
collections::VecDeque, collections::VecDeque,
future::poll_fn, future::poll_fn,
io, io, mem,
pin::Pin, pin::Pin,
task::{Context, Poll}, task::{Context, Poll},
}; };
@ -102,13 +102,13 @@ impl Stream for StreamingBody {
} }
while let Some(msg) = this.messages.pop_front() { while let Some(msg) = this.messages.pop_front() {
if let Err(e) = this.codec.encode(msg, &mut this.buf) { if let Err(err) = this.codec.encode(msg, &mut this.buf) {
return Poll::Ready(Some(Err(e.into()))); return Poll::Ready(Some(Err(err.into())));
} }
} }
if !this.buf.is_empty() { 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 Poll::Pending

View File

@ -1,6 +1,9 @@
use std::sync::{ use std::{
fmt,
sync::{
atomic::{AtomicBool, Ordering}, atomic::{AtomicBool, Ordering},
Arc, Arc,
},
}; };
use actix_http::ws::{CloseReason, Item, Message}; use actix_http::ws::{CloseReason, Item, Message};
@ -10,7 +13,7 @@ use tokio::sync::mpsc::Sender;
/// A handle into the websocket session. /// 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)] #[derive(Clone)]
pub struct Session { pub struct Session {
inner: Option<Sender<Message>>, inner: Option<Sender<Message>>,
@ -21,9 +24,9 @@ pub struct Session {
#[derive(Debug)] #[derive(Debug)]
pub struct Closed; pub struct Closed;
impl std::fmt::Display for Closed { impl fmt::Display for Closed {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Session is closed") f.write_str("Session is closed")
} }
} }
@ -43,7 +46,7 @@ impl Session {
} }
} }
/// Send text into the websocket /// Sends text into the WebSocket.
/// ///
/// ```no_run /// ```no_run
/// # use actix_ws::Session; /// # use actix_ws::Session;
@ -65,7 +68,7 @@ impl Session {
} }
} }
/// Send raw bytes into the websocket /// Sends raw bytes into the WebSocket.
/// ///
/// ```no_run /// ```no_run
/// # use actix_ws::Session; /// # 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 /// For many applications, it will be important to send regular pings to keep track of if the
/// client has disconnected /// client has disconnected
@ -112,7 +115,7 @@ impl Session {
} }
} }
/// Pong the client /// Pongs the client.
/// ///
/// ```no_run /// ```no_run
/// # use actix_ws::{Message, Session}; /// # 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 /// 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 /// 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 /// ```no_run
/// # use actix_ws::{Closed, Session}; /// # use actix_ws::{Closed, Session};
@ -180,6 +183,7 @@ impl Session {
/// ``` /// ```
pub async fn close(mut self, reason: Option<CloseReason>) -> Result<(), Closed> { pub async fn close(mut self, reason: Option<CloseReason>) -> Result<(), Closed> {
self.pre_check(); self.pre_check();
if let Some(inner) = self.inner.take() { if let Some(inner) = self.inner.take() {
self.closed.store(true, Ordering::Relaxed); self.closed.store(true, Ordering::Relaxed);
inner.send(Message::Close(reason)).await.map_err(|_| Closed) inner.send(Message::Close(reason)).await.map_err(|_| Closed)