Function len_ascii

Source
pub fn len_ascii<R: Read, W: Write>(
    len: usize,
) -> (impl ReadFn<R, String>, impl WriteFn<W, String>)
Expand description

Reads/Writes a ascii string from a stream given its length.

§Remarks

The only difference between len_ascii and len_utf8 is the ascii check that fails if the string is not ascii. Use len_utf8 instead if you want to avoid that.

§Panics

If the input string is not ascii (NOT if the string that has just been read is not ascii, in that case it will just return an error) the function panics.

§Examples

use std::io::Cursor;
use bin_io::strings::len_ascii;
use bin_io::read;
 
let vec = vec![ 0x42, 0x61, 0x72 ];
let mut cursor = Cursor::new(vec);
 
let string = read(&mut cursor, len_ascii(3))
    .unwrap();
 
assert_eq!(string, "Bar");