Add public type aliases for the stream types used by the various client-side functions

Fixes https://github.com/sdroege/async-tungstenite/issues/35
pull/38/head
Sebastian Dröge 5 years ago committed by Sebastian Dröge
parent be8e9d898d
commit 8738c887c0
  1. 20
      src/async_std.rs
  2. 11
      src/async_tls.rs
  3. 7
      src/gio.rs
  4. 3
      src/lib.rs
  5. 44
      src/tokio.rs

@ -154,13 +154,16 @@ type Connector = real_async_tls::TlsConnector;
#[cfg(feature = "async-native-tls")]
use self::async_native_tls::{client_async_tls_with_connector_and_config, AutoStream, Connector};
/// Type alias for the stream type of the `client_async()` functions.
pub type ClientStream<S> = AutoStream<S>;
#[cfg(feature = "async-native-tls")]
/// Creates a WebSocket handshake from a request and a stream,
/// upgrading the stream to TLS if required.
pub async fn client_async_tls<R, S>(
request: R,
stream: S,
) -> Result<(WebSocketStream<AutoStream<S>>, Response), Error>
) -> Result<(WebSocketStream<ClientStream<S>>, Response), Error>
where
R: IntoClientRequest + Unpin,
S: 'static + AsyncRead + AsyncWrite + Unpin,
@ -177,7 +180,7 @@ pub async fn client_async_tls_with_config<R, S>(
request: R,
stream: S,
config: Option<WebSocketConfig>,
) -> Result<(WebSocketStream<AutoStream<S>>, Response), Error>
) -> Result<(WebSocketStream<ClientStream<S>>, Response), Error>
where
R: IntoClientRequest + Unpin,
S: 'static + AsyncRead + AsyncWrite + Unpin,
@ -194,7 +197,7 @@ pub async fn client_async_tls_with_connector<R, S>(
request: R,
stream: S,
connector: Option<Connector>,
) -> Result<(WebSocketStream<AutoStream<S>>, Response), Error>
) -> Result<(WebSocketStream<ClientStream<S>>, Response), Error>
where
R: IntoClientRequest + Unpin,
S: 'static + AsyncRead + AsyncWrite + Unpin,
@ -203,10 +206,13 @@ where
client_async_tls_with_connector_and_config(request, stream, connector, None).await
}
/// Type alias for the stream type of the `connect_async()` functions.
pub type ConnectStream = ClientStream<TcpStream>;
/// Connect to a given URL.
pub async fn connect_async<R>(
request: R,
) -> Result<(WebSocketStream<AutoStream<TcpStream>>, Response), Error>
) -> Result<(WebSocketStream<ConnectStream>, Response), Error>
where
R: IntoClientRequest + Unpin,
{
@ -217,7 +223,7 @@ where
pub async fn connect_async_with_config<R>(
request: R,
config: Option<WebSocketConfig>,
) -> Result<(WebSocketStream<AutoStream<TcpStream>>, Response), Error>
) -> Result<(WebSocketStream<ConnectStream>, Response), Error>
where
R: IntoClientRequest + Unpin,
{
@ -236,7 +242,7 @@ where
pub async fn connect_async_with_tls_connector<R>(
request: R,
connector: Option<Connector>,
) -> Result<(WebSocketStream<AutoStream<TcpStream>>, Response), Error>
) -> Result<(WebSocketStream<ConnectStream>, Response), Error>
where
R: IntoClientRequest + Unpin,
{
@ -249,7 +255,7 @@ pub async fn connect_async_with_tls_connector_and_config<R>(
request: R,
connector: Option<Connector>,
config: Option<WebSocketConfig>,
) -> Result<(WebSocketStream<AutoStream<TcpStream>>, Response), Error>
) -> Result<(WebSocketStream<ConnectStream>, Response), Error>
where
R: IntoClientRequest + Unpin,
{

@ -42,12 +42,15 @@ where
}
}
/// Type alias for the stream type of the `client_async()` functions.
pub type ClientStream<S> = AutoStream<S>;
/// Creates a WebSocket handshake from a request and a stream,
/// upgrading the stream to TLS if required.
pub async fn client_async_tls<R, S>(
request: R,
stream: S,
) -> Result<(WebSocketStream<AutoStream<S>>, Response), Error>
) -> Result<(WebSocketStream<ClientStream<S>>, Response), Error>
where
R: IntoClientRequest + Unpin,
S: 'static + AsyncRead + AsyncWrite + Unpin,
@ -63,7 +66,7 @@ pub async fn client_async_tls_with_config<R, S>(
request: R,
stream: S,
config: Option<WebSocketConfig>,
) -> Result<(WebSocketStream<AutoStream<S>>, Response), Error>
) -> Result<(WebSocketStream<ClientStream<S>>, Response), Error>
where
R: IntoClientRequest + Unpin,
S: 'static + AsyncRead + AsyncWrite + Unpin,
@ -79,7 +82,7 @@ pub async fn client_async_tls_with_connector<R, S>(
request: R,
stream: S,
connector: Option<AsyncTlsConnector>,
) -> Result<(WebSocketStream<AutoStream<S>>, Response), Error>
) -> Result<(WebSocketStream<ClientStream<S>>, Response), Error>
where
R: IntoClientRequest + Unpin,
S: 'static + AsyncRead + AsyncWrite + Unpin,
@ -96,7 +99,7 @@ pub async fn client_async_tls_with_connector_and_config<R, S>(
stream: S,
connector: Option<AsyncTlsConnector>,
config: Option<WebSocketConfig>,
) -> Result<(WebSocketStream<AutoStream<S>>, Response), Error>
) -> Result<(WebSocketStream<ClientStream<S>>, Response), Error>
where
R: IntoClientRequest + Unpin,
S: 'static + AsyncRead + AsyncWrite + Unpin,

@ -13,12 +13,13 @@ use tungstenite::stream::Mode;
use crate::{client_async_with_config, domain, port, Response, WebSocketConfig, WebSocketStream};
type MaybeTlsStream = IOStreamAsyncReadWrite<gio::SocketConnection>;
/// Type alias for the stream type of the `connect_async()` functions.
pub type ConnectStream = IOStreamAsyncReadWrite<gio::SocketConnection>;
/// Connect to a given URL.
pub async fn connect_async<R>(
request: R,
) -> Result<(WebSocketStream<MaybeTlsStream>, Response), Error>
) -> Result<(WebSocketStream<ConnectStream>, Response), Error>
where
R: IntoClientRequest + Unpin,
{
@ -29,7 +30,7 @@ where
pub async fn connect_async_with_config<R>(
request: R,
config: Option<WebSocketConfig>,
) -> Result<(WebSocketStream<MaybeTlsStream>, Response), Error>
) -> Result<(WebSocketStream<ConnectStream>, Response), Error>
where
R: IntoClientRequest + Unpin,
{

@ -272,8 +272,7 @@ impl<S> WebSocketStream<S> {
}
/// Returns a reference to the configuration of the tungstenite stream.
pub fn get_config(&self) -> &WebSocketConfig
{
pub fn get_config(&self) -> &WebSocketConfig {
self.inner.get_config()
}

@ -152,13 +152,16 @@ type Connector = real_async_tls::TlsConnector;
#[cfg(feature = "tokio-native-tls")]
use self::tokio_tls::{client_async_tls_with_connector_and_config, AutoStream, Connector};
/// Type alias for the stream type of the `client_async()` functions.
pub type ClientStream<S> = AutoStream<S>;
#[cfg(feature = "tokio-native-tls")]
/// Creates a WebSocket handshake from a request and a stream,
/// upgrading the stream to TLS if required.
pub async fn client_async_tls<R, S>(
request: R,
stream: S,
) -> Result<(WebSocketStream<AutoStream<S>>, Response), Error>
) -> Result<(WebSocketStream<ClientStream<S>>, Response), Error>
where
R: IntoClientRequest + Unpin,
S: 'static + AsyncRead + AsyncWrite + Unpin,
@ -175,7 +178,7 @@ pub async fn client_async_tls_with_config<R, S>(
request: R,
stream: S,
config: Option<WebSocketConfig>,
) -> Result<(WebSocketStream<AutoStream<S>>, Response), Error>
) -> Result<(WebSocketStream<ClientStream<S>>, Response), Error>
where
R: IntoClientRequest + Unpin,
S: 'static + AsyncRead + AsyncWrite + Unpin,
@ -192,7 +195,7 @@ pub async fn client_async_tls_with_connector<R, S>(
request: R,
stream: S,
connector: Option<Connector>,
) -> Result<(WebSocketStream<AutoStream<S>>, Response), Error>
) -> Result<(WebSocketStream<ClientStream<S>>, Response), Error>
where
R: IntoClientRequest + Unpin,
S: 'static + AsyncRead + AsyncWrite + Unpin,
@ -201,16 +204,13 @@ where
client_async_tls_with_connector_and_config(request, stream, connector, None).await
}
/// Type alias for the stream type of the `connect_async()` functions.
pub type ConnectStream = ClientStream<TokioAdapter<TcpStream>>;
/// Connect to a given URL.
pub async fn connect_async<R>(
request: R,
) -> Result<
(
WebSocketStream<AutoStream<TokioAdapter<TcpStream>>>,
Response,
),
Error,
>
) -> Result<(WebSocketStream<ConnectStream>, Response), Error>
where
R: IntoClientRequest + Unpin,
{
@ -221,13 +221,7 @@ where
pub async fn connect_async_with_config<R>(
request: R,
config: Option<WebSocketConfig>,
) -> Result<
(
WebSocketStream<AutoStream<TokioAdapter<TcpStream>>>,
Response,
),
Error,
>
) -> Result<(WebSocketStream<ConnectStream>, Response), Error>
where
R: IntoClientRequest + Unpin,
{
@ -246,13 +240,7 @@ where
pub async fn connect_async_with_tls_connector<R>(
request: R,
connector: Option<Connector>,
) -> Result<
(
WebSocketStream<AutoStream<TokioAdapter<TcpStream>>>,
Response,
),
Error,
>
) -> Result<(WebSocketStream<ConnectStream>, Response), Error>
where
R: IntoClientRequest + Unpin,
{
@ -265,13 +253,7 @@ pub async fn connect_async_with_tls_connector_and_config<R>(
request: R,
connector: Option<Connector>,
config: Option<WebSocketConfig>,
) -> Result<
(
WebSocketStream<AutoStream<TokioAdapter<TcpStream>>>,
Response,
),
Error,
>
) -> Result<(WebSocketStream<ConnectStream>, Response), Error>
where
R: IntoClientRequest + Unpin,
{

Loading…
Cancel
Save