pub async fn new(mut stream: S, version_specifiers: &[u32; 4]) -> ConnectionResult<Self> {
        let mut version_specifiers_bytes = BytesMut::with_capacity(16);
        version_specifiers
            .iter()
            .for_each(|&v| version_specifiers_bytes.put_u32(v));
        stream.write_all(&PREAMBLE).await?;
        stream.write_all(&version_specifiers_bytes).await?;
        stream.flush().await?;

        let mut u32_bytes = [0, 0, 0, 0];
        stream.read_exact(&mut u32_bytes).await?;
        let version = u32::from_be_bytes(u32_bytes);

        if version > 0 {
            for &specifier in version_specifiers {
                if is_compatible(version, specifier) {
                    return Ok(Self {
                        stream,
                        version,
                        server_state: Connected,
                        sent_queue: Default::default(),
                    });
                }
            }
        }
        Err(ConnectionError::HandshakeFailed(*version_specifiers))
    }
/// Attempt to create a new client from an asynchronous stream. A handshake will be performed
/// with the provided protocol version specifiers, and, if this succeeds, a Client will be
/// returned.
Attempt to create a new client from an asynchronous stream. A handshake will be performed
with the provided protocol version specifiers, and, if this succeeds, a Client will be
returned.
Attempt to create a new client from an asynchronous stream . A handshake will be performed with the provided protocol version specifiers and if this succeeds a Client will be returned .
pub async fn new(mut stream: S, version_specifiers: &[u32; 4]) -> ConnectionResult<Self> {
        let mut version_specifiers_bytes = BytesMut::with_capacity(16);
        version_specifiers
            .iter()
            .for_each(|&v| version_specifiers_bytes.put_u32(v));
        stream.write_all(&PREAMBLE).await?;
        stream.write_all(&version_specifiers_bytes).await?;
        stream.flush().await?;
        let mut u32_bytes = [0, 0, 0, 0];
        stream.read_exact(&mut u32_bytes).await?;
        let version = u32::from_be_bytes(u32_bytes);
        if version > 0 {
            for &specifier in version_specifiers {
                if is_compatible(version, specifier) {
                    return Ok(Self {
                        stream,
                        version,
                        server_state: Connected,
                        sent_queue: Default::default(),
                    });
                }
            }
        }
        Err(ConnectionError::HandshakeFailed(*version_specifiers))
    }
pub async fn new ( mut stream : S , version_specifiers : & [ u32 ; 4 ] ) -> ConnectionResult < Self > { let mut version_specifiers_bytes = BytesMut :: with_capacity ( 16 ) ; version_specifiers . iter ( ) . for_each ( | & v | version_specifiers_bytes . put_u32 ( v ) ) ; stream . write_all ( & PREAMBLE ) . await ? ; stream . write_all ( & version_specifiers_bytes ) . await ? ; stream . flush ( ) . await ? ; let mut u32_bytes = [ 0 , 0 , 0 , 0 ] ; stream . read_exact ( & mut u32_bytes ) . await ? ; let version = u32 :: from_be_bytes ( u32_bytes ) ; if version > 0 { for & specifier in version_specifiers { if is_compatible ( version , specifier ) { return Ok ( Self { stream , version , server_state : Connected , sent_queue : Default :: default ( ) , } ) ; } } } Err ( ConnectionError :: HandshakeFailed ( * version_specifiers ) ) }
Attempt to create a new client from an asynchronous stream.
Attempt to create a new client from an asynchronous stream .
stream
S
version_specifiers
&[u32; 4]