Skip to content

Commit

Permalink
Additional Documentation of IntoClientRequest on connect_async (#342
Browse files Browse the repository at this point in the history
)

* Add documentation to `connect_async`

* Add hidden async wrapper function

* Reduce example, fix doc format

* Avoid `main` as the test function name

---------

Co-authored-by: Brendan Blanchard <brendano257@gmail.com>
  • Loading branch information
Brendan-Blanchard and brendano257 authored Aug 8, 2024
1 parent 8325825 commit 94a35a0
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ use tungstenite::{
use crate::{domain, stream::MaybeTlsStream, Connector, IntoClientRequest, WebSocketStream};

/// 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 tokio_tungstenite::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<R>(
request: R,
) -> Result<(WebSocketStream<MaybeTlsStream<TcpStream>>, Response), Error>
Expand Down

0 comments on commit 94a35a0

Please sign in to comment.