From 0e4e0ab5f930e2c84a034871b4b8cea8509ecce4 Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Mon, 7 Sep 2020 09:56:42 +0300 Subject: [PATCH 1/3] Improve awc websocket docs --- awc/src/lib.rs | 3 ++- awc/src/ws.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/awc/src/lib.rs b/awc/src/lib.rs index 1cc31a194e4..1607d5a4b07 100644 --- a/awc/src/lib.rs +++ b/awc/src/lib.rs @@ -193,7 +193,8 @@ impl Client { self.request(Method::OPTIONS, url) } - /// Construct WebSockets request. + /// Initialize a WebSockets connection. + /// This method returns a builder structure to establish a WebSocket connection. pub fn ws(&self, url: U) -> ws::WebsocketsRequest where Uri: TryFrom, diff --git a/awc/src/ws.rs b/awc/src/ws.rs index 8b01e571650..42498cb638e 100644 --- a/awc/src/ws.rs +++ b/awc/src/ws.rs @@ -1,4 +1,33 @@ //! Websockets client +//! +//! This module contains type definitions required to use [`awc::Client`](../struct.Client.html) as a WebSocket client. +//! To use `awc::Client` +//! +//! # Example +//! +//! ``` +//! use awc::{Client, ws}; +//! use futures_util::{sink::SinkExt, stream::StreamExt}; +//! +//! #[actix_rt::main] +//! async fn main() { +//! let (_resp, mut connection) = Client::new() +//! .ws("wss://echo.websocket.org") +//! .connect() +//! .await +//! .unwrap(); +//! +//! connection +//! .send(ws::Message::Text("Echo".to_string())) +//! .await +//! .unwrap(); +//! let response = connection.next().await.unwrap().unwrap(); +//! +//! assert_eq!(response, ws::Frame::Text("Echo".as_bytes().into())); +//! } +//! ``` +//! + use std::convert::TryFrom; use std::net::SocketAddr; use std::rc::Rc; From 93bc3a7dd0d8a0f12a913a52a3f2d6ec87858b8a Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Mon, 7 Sep 2020 13:14:42 +0300 Subject: [PATCH 2/3] Use ws instead of wss in the doc-test --- awc/src/ws.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awc/src/ws.rs b/awc/src/ws.rs index 42498cb638e..1f53df63aa0 100644 --- a/awc/src/ws.rs +++ b/awc/src/ws.rs @@ -12,7 +12,7 @@ //! #[actix_rt::main] //! async fn main() { //! let (_resp, mut connection) = Client::new() -//! .ws("wss://echo.websocket.org") +//! .ws("ws://echo.websocket.org") //! .connect() //! .await //! .unwrap(); From ba9a09ba9ec5e0efb5091e91cd0f62cc9dfbcb52 Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Mon, 7 Sep 2020 13:34:53 +0300 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Rob Ede --- awc/src/lib.rs | 4 ++-- awc/src/ws.rs | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/awc/src/lib.rs b/awc/src/lib.rs index 1607d5a4b07..a98d6767d06 100644 --- a/awc/src/lib.rs +++ b/awc/src/lib.rs @@ -193,8 +193,8 @@ impl Client { self.request(Method::OPTIONS, url) } - /// Initialize a WebSockets connection. - /// This method returns a builder structure to establish a WebSocket connection. + /// Initialize a WebSocket connection. + /// Returns a WebSocket connection builder. pub fn ws(&self, url: U) -> ws::WebsocketsRequest where Uri: TryFrom, diff --git a/awc/src/ws.rs b/awc/src/ws.rs index 1f53df63aa0..96687ac7489 100644 --- a/awc/src/ws.rs +++ b/awc/src/ws.rs @@ -1,7 +1,6 @@ //! Websockets client //! -//! This module contains type definitions required to use [`awc::Client`](../struct.Client.html) as a WebSocket client. -//! To use `awc::Client` +//! Type definitions required to use [`awc::Client`](../struct.Client.html) as a WebSocket client. //! //! # Example //! @@ -26,7 +25,6 @@ //! assert_eq!(response, ws::Frame::Text("Echo".as_bytes().into())); //! } //! ``` -//! use std::convert::TryFrom; use std::net::SocketAddr;