pub fn read_from_stream(stream: &mut TcpStream) -> Result<Vec<u8>, std::io::ErrorKind> {
    // Figure out the size of the incoming message
    let mut size = [0u8; 2];
    if let Err(e) = stream.read_exact(&mut size) {
        return Err(e.kind());
    }
    let size = u16::from_be_bytes(size);

    // Get the actual message
    let mut bytes = vec![0u8; size as usize];
    if let Err(e) = stream.read_exact(&mut bytes) {
        return Err(e.kind());
    }
    Ok(bytes)
}
/// Reads 1 message from stream
/// Returns `Ok(bytes)` if the reading was successful
/// and `Err(e)` if an error was encountered while reading
Reads 1 message from stream
Returns `Ok(bytes)` if the reading was successful
and `Err(e)` if an error was encountered while reading
Reads 1 message from stream Returns ` Ok ( bytes ) ` if the reading was successful and ` Err ( e ) ` if an error was encountered while reading
pub fn read_from_stream(stream: &mut TcpStream) -> Result<Vec<u8>, std::io::ErrorKind> {
    // Figure out the size of the incoming message
    let mut size = [0u8; 2];
    if let Err(e) = stream.read_exact(&mut size) {
        return Err(e.kind());
    }
    let size = u16::from_be_bytes(size);
    // Get the actual message
    let mut bytes = vec![0u8; size as usize];
    if let Err(e) = stream.read_exact(&mut bytes) {
        return Err(e.kind());
    }
    Ok(bytes)
}
pub fn read_from_stream ( stream : & mut TcpStream ) -> Result < Vec < u8 > , std :: io :: ErrorKind > { // Figure out the size of the incoming message let mut size = [ 0u8 ; 2 ] ; if let Err ( e ) = stream . read_exact ( & mut size ) { return Err ( e . kind ( ) ) ; } let size = u16 :: from_be_bytes ( size ) ; // Get the actual message let mut bytes = vec ! [ 0u8 size as usize ] ; if let Err ( e ) = stream . read_exact ( & mut bytes ) { return Err ( e . kind ( ) ) ; } Ok ( bytes ) }
Reads 1 message from stream
Returns `Ok(bytes)` if the reading was successful
and `Err(e)` if an error was encountered while reading
Reads 1 message from stream Returns ` Ok ( bytes ) ` if the reading was successful and ` Err ( e ) ` if an error was encountered while reading
stream
&mut TcpStream
stream
&mut TcpStream