pub fn read_from_stream<R : Read, T: for<'de> Deserialize<'de>>
    (stream : &mut R) -> Result<T, Error> {

    let mut length = [0u8; 2];
    if let Err(_) = stream.read_exact(&mut length) {
        return Err(Error::NetworkReadError);
    }

    let l = u16::from_be_bytes(length);
    if l == 0 {
        return Err(Error::PayloadSizeZero);
    }

    let mut buf = vec!(0u8; l as usize);

    if let Err(_) = stream.read_exact(&mut buf) {
        return Err(Error::NetworkReadError);
    }

    match serde_json::from_slice(&buf) {
        Ok(s)   => Ok(s),
        Err(_)  => Err(Error::DeserializationError)
    }
}
/// This function reads a struct that implements the `Deserialize` trait from an input stream
/// The input stream must implement the `std::io::Read` trait
///
/// Returns a `Result` wrapping the struct read from the stream
///
/// # Arguments
///
/// * `stream` - The input stream
This function reads a struct that implements the `Deserialize` trait from an input stream
The input stream must implement the `std::io::Read` trait

Returns a `Result` wrapping the struct read from the stream
This function reads a struct that implements the ` Deserialize ` trait from an input stream The input stream must implement the ` std :: io :: Read ` trait Returns a ` Result ` wrapping the struct read from the stream
pub fn read_from_stream<R : Read, T: for<'de> Deserialize<'de>>
    (stream : &mut R) -> Result<T, Error> {
    let mut length = [0u8; 2];
    if let Err(_) = stream.read_exact(&mut length) {
        return Err(Error::NetworkReadError);
    }
    let l = u16::from_be_bytes(length);
    if l == 0 {
        return Err(Error::PayloadSizeZero);
    }
    let mut buf = vec!(0u8; l as usize);
    if let Err(_) = stream.read_exact(&mut buf) {
        return Err(Error::NetworkReadError);
    }
    match serde_json::from_slice(&buf) {
        Ok(s)   => Ok(s),
        Err(_)  => Err(Error::DeserializationError)
    }
}
pub fn read_from_stream < R : Read , T : for < ' de > Deserialize < ' de > > ( stream : & mut R ) -> Result < T , Error > { let mut length = [ 0u8 ; 2 ] ; if let Err ( _ ) = stream . read_exact ( & mut length ) { return Err ( Error :: NetworkReadError ) ; } let l = u16 :: from_be_bytes ( length ) ; if l == 0 { return Err ( Error :: PayloadSizeZero ) ; } let mut buf = vec ! ( 0u8 l as usize ) ; if let Err ( _ ) = stream . read_exact ( & mut buf ) { return Err ( Error :: NetworkReadError ) ; } match serde_json :: from_slice ( & buf ) { Ok ( s ) => Ok ( s ) , Err ( _ ) => Err ( Error :: DeserializationError ) } }
This function reads a struct that implements the `Deserialize` trait from an input stream
The input stream must implement the `std::io::Read` trait
This function reads a struct that implements the ` Deserialize ` trait from an input stream The input stream must implement the ` std :: io :: Read ` trait
stream
&mut R
stream
&mut R