Module io

Module io 

Source
Expand description

I/O utility implementations for TryNext and TryNextWithContext.

This module provides implementations of the TryNext and TryNextWithContext traits for BufReader, enabling incremental, fallible reading of bytes from any Read stream.

These traits abstract over iterating through potentially fallible sources that yield elements asynchronously or sequentially. By implementing them for BufReader, this module allows buffered reading of single bytes in a way that works well for streaming parsers or byte-oriented protocols.

§Features

This module is only available when the std feature is enabled.

§Example

use std::io::BufReader;
use try_next::{TryNext, TryNextWithContext};

let data = b"abc";
let mut reader = BufReader::new(&data[..]);

assert_eq!(reader.try_next().unwrap(), Some(b'a'));
assert_eq!(reader.try_next().unwrap(), Some(b'b'));
assert_eq!(reader.try_next().unwrap(), Some(b'c'));
assert_eq!(reader.try_next().unwrap(), None);