diff --git a/src/async_std.rs b/src/async_std.rs index 51cf55a..767f3aa 100644 --- a/src/async_std.rs +++ b/src/async_std.rs @@ -221,6 +221,24 @@ where pub type ConnectStream = ClientStream; /// Connect to a given URL. +/// +/// Accepts any request that implements [`IntoClientRequest`], which is often just `&str`, but can +/// be a variety of types such as `httparse::Request` or [`tungstenite::http::Request`] for more +/// complex uses. +/// +/// ```no_run +/// # use tungstenite::client::IntoClientRequest; +/// +/// # async fn test() { +/// use tungstenite::http::{Method, Request}; +/// use async_tungstenite::async_std::connect_async; +/// +/// let mut request = "wss://api.example.com".into_client_request().unwrap(); +/// request.headers_mut().insert("api-key", "42".parse().unwrap()); +/// +/// let (stream, response) = connect_async(request).await.unwrap(); +/// # } +/// ``` pub async fn connect_async( request: R, ) -> Result<(WebSocketStream, Response), Error> diff --git a/src/gio.rs b/src/gio.rs index ec66c0e..a6aa9ec 100644 --- a/src/gio.rs +++ b/src/gio.rs @@ -18,6 +18,24 @@ use crate::{client_async_with_config, domain, port, Response, WebSocketConfig, W pub type ConnectStream = IOStreamAsyncReadWrite; /// Connect to a given URL. +/// +/// Accepts any request that implements [`IntoClientRequest`], which is often just `&str`, but can +/// be a variety of types such as `httparse::Request` or [`tungstenite::http::Request`] for more +/// complex uses. +/// +/// ```no_run +/// # use tungstenite::client::IntoClientRequest; +/// +/// # async fn test() { +/// use tungstenite::http::{Method, Request}; +/// use async_tungstenite::gio::connect_async; +/// +/// let mut request = "wss://api.example.com".into_client_request().unwrap(); +/// request.headers_mut().insert("api-key", "42".parse().unwrap()); +/// +/// let (stream, response) = connect_async(request).await.unwrap(); +/// # } +/// ``` pub async fn connect_async( request: R, ) -> Result<(WebSocketStream, Response), Error> diff --git a/src/tokio.rs b/src/tokio.rs index 362bce3..320eb08 100644 --- a/src/tokio.rs +++ b/src/tokio.rs @@ -362,6 +362,24 @@ where pub type ConnectStream = ClientStream; /// Connect to a given URL. +/// +/// Accepts any request that implements [`IntoClientRequest`], which is often just `&str`, but can +/// be a variety of types such as `httparse::Request` or [`tungstenite::http::Request`] for more +/// complex uses. +/// +/// ```no_run +/// # use tungstenite::client::IntoClientRequest; +/// +/// # async fn test() { +/// use tungstenite::http::{Method, Request}; +/// use async_tungstenite::tokio::connect_async; +/// +/// let mut request = "wss://api.example.com".into_client_request().unwrap(); +/// request.headers_mut().insert("api-key", "42".parse().unwrap()); +/// +/// let (stream, response) = connect_async(request).await.unwrap(); +/// # } +/// ``` pub async fn connect_async( request: R, ) -> Result<(WebSocketStream, Response), Error>