pub async fn recv(&mut self) -> Result<&[u8], RecvError> {
        if let Some((packet, in_pos)) = &self.in_packet {
            if *in_pos == packet.len() {
                self.in_packet = None;
            }
        }

        if self.in_packet.is_none() {
            let packet = self
                .incoming_packets
                .next()
                .await
                .ok_or(RecvError::Disconnected)?;
            self.in_packet = Some((packet, 0));
        }
        let (packet, in_pos) = self.in_packet.as_mut().unwrap();

        if *in_pos + 2 > packet.len() {
            *in_pos = packet.len();
            return Err(RecvError::BadFormat);
        }
        let length = LittleEndian::read_u16(&packet[*in_pos..*in_pos + 2]) as usize;
        *in_pos += 2;

        if *in_pos + length > packet.len() {
            *in_pos = packet.len();
            return Err(RecvError::BadFormat);
        }

        let msg = &packet[*in_pos..*in_pos + length];
        *in_pos += length;

        Ok(msg)
    }
/// Receive a message into the provide buffer.
///
/// If the received message fits into the provided buffer, this will return `Ok(message_len)`,
/// otherwise it will return `Err(RecvError::TooBig)`.
///
/// This method is cancel safe, it will never partially read a message or drop received
/// messages.
Receive a message into the provide buffer.
If the received message fits into the provided buffer, this will return `Ok(message_len)`,
otherwise it will return `Err(RecvError::TooBig)`.

This method is cancel safe, it will never partially read a message or drop received
messages.
Receive a message into the provide buffer . If the received message fits into the provided buffer this will return ` Ok ( message_len ) ` otherwise it will return ` Err ( RecvError :: TooBig ) ` . This method is cancel safe it will never partially read a message or drop received messages .
pub async fn recv(&mut self) -> Result<&[u8], RecvError> {
        if let Some((packet, in_pos)) = &self.in_packet {
            if *in_pos == packet.len() {
                self.in_packet = None;
            }
        }
        if self.in_packet.is_none() {
            let packet = self
                .incoming_packets
                .next()
                .await
                .ok_or(RecvError::Disconnected)?;
            self.in_packet = Some((packet, 0));
        }
        let (packet, in_pos) = self.in_packet.as_mut().unwrap();
        if *in_pos + 2 > packet.len() {
            *in_pos = packet.len();
            return Err(RecvError::BadFormat);
        }
        let length = LittleEndian::read_u16(&packet[*in_pos..*in_pos + 2]) as usize;
        *in_pos += 2;
        if *in_pos + length > packet.len() {
            *in_pos = packet.len();
            return Err(RecvError::BadFormat);
        }
        let msg = &packet[*in_pos..*in_pos + length];
        *in_pos += length;
        Ok(msg)
    }
pub async fn recv ( & mut self ) -> Result < & [ u8 ] , RecvError > { if let Some ( ( packet , in_pos ) ) = & self . in_packet { if * in_pos == packet . len ( ) { self . in_packet = None ; } } if self . in_packet . is_none ( ) { let packet = self . incoming_packets . next ( ) . await . ok_or ( RecvError :: Disconnected ) ? ; self . in_packet = Some ( ( packet , 0 ) ) ; } let ( packet , in_pos ) = self . in_packet . as_mut ( ) . unwrap ( ) ; if * in_pos + 2 > packet . len ( ) { * in_pos = packet . len ( ) ; return Err ( RecvError :: BadFormat ) ; } let length = LittleEndian :: read_u16 ( & packet [ * in_pos .. * in_pos + 2 ] ) as usize ; * in_pos += 2 ; if * in_pos + length > packet . len ( ) { * in_pos = packet . len ( ) ; return Err ( RecvError :: BadFormat ) ; } let msg = & packet [ * in_pos .. * in_pos + length ] ; * in_pos += length ; Ok ( msg ) }
Receive a message into the provide buffer.
Receive a message into the provide buffer .
&mut self
&mut self