pub async fn read_while_any_async<R: AsyncBufRead + Unpin>(
reader: &mut R,
check_set: &[u8],
to: &mut Vec<u8>,
) -> Result<(u8, usize)>
Expand description
Async version of read_while_any
for streaming data.
This function provides the same functionality as read_while_any
but works with
async streams, making it perfect for processing network data, file streams, or any
other async I/O operations.
§Arguments
reader
- An AsyncBufRead stream to read fromcheck_set
- A slice of bytes to match againstto
- Buffer to store the read data
§Returns
Returns a tuple containing:
- The first byte that didn’t match (the stop byte)
- The number of bytes read
§Examples
use async_regex::read_while_any_async;
use futures::io::Cursor;
use tokio::runtime::Runtime;
let rt = Runtime::new().unwrap();
rt.block_on(async {
let mut reader = Cursor::new(b"aaaaabbbccc");
let mut buffer = Vec::new();
let check_set = b"ab";
let (stop_byte, count) = read_while_any_async(&mut reader, check_set, &mut buffer).await.unwrap();
assert_eq!(buffer, b"aaaaabbb");
assert_eq!(stop_byte, b'c');
});