1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
use super::error::{Error, Result};
use tracing::debug;
use url::Url;

use super::super::ShardStream;

pub async fn connect(url: &str) -> Result<ShardStream> {
    let url = Url::parse(url).map_err(|source| Error::ParsingUrl {
        source,
        url: url.to_owned(),
    })?;

    let (stream, _) = async_tungstenite::tokio::connect_async(url)
        .await
        .map_err(|source| Error::Connecting { source })?;

    debug!("Shook hands with remote");

    Ok(stream)
}