pub fn read_sized_string(fd: &mut File, size: usize)
                         -> Result<String, NrgError> {
    // Read size bytes
    let mut bytes = vec!(0u8; size);
    try!(fd.read_exact(&mut bytes));

    // Truncate the vector at the first null byte
    let mut i: usize = 0;
    for b in bytes.iter() {
        if *b == 0 { break; }
        i += 1;
    }
    bytes.truncate(i);

    let cstring = CString::new(bytes)
        .expect("This Vec wasn't supposed to contain any null byte!");

    cstring.into_string().map_err(NrgError::String)
}
/// Reads a String of `size` bytes from `fd`.
///
/// The string will be truncated at the first null byte encountered; therefore,
/// its length may be less than `size` characters.
Reads a String of `size` bytes from `fd`.
The string will be truncated at the first null byte encountered; therefore,
its length may be less than `size` characters.
Reads a String of ` size ` bytes from ` fd ` . The string will be truncated at the first null byte encountered ; therefore its length may be less than ` size ` characters .
pub fn read_sized_string(fd: &mut File, size: usize)
                         -> Result<String, NrgError> {
    // Read size bytes
    let mut bytes = vec!(0u8; size);
    try!(fd.read_exact(&mut bytes));
    // Truncate the vector at the first null byte
    let mut i: usize = 0;
    for b in bytes.iter() {
        if *b == 0 { break; }
        i += 1;
    }
    bytes.truncate(i);
    let cstring = CString::new(bytes)
        .expect("This Vec wasn't supposed to contain any null byte!");
    cstring.into_string().map_err(NrgError::String)
}
pub fn read_sized_string ( fd : & mut File , size : usize ) -> Result < String , NrgError > { // Read size bytes let mut bytes = vec ! ( 0u8 size ) ; try ! ( fd read_exact ( mut bytes ) ) ; // Truncate the vector at the first null byte let mut i : usize = 0 ; for b in bytes . iter ( ) { if * b == 0 { break ; } i += 1 ; } bytes . truncate ( i ) ; let cstring = CString :: new ( bytes ) . expect ( " " ) ; cstring . into_string ( ) . map_err ( NrgError :: String ) }
Reads a String of `size` bytes from `fd`.
Reads a String of ` size ` bytes from ` fd ` .
fd
&mut File
size
usize
fd
&mut File
size
usize