mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-07 00:00:08 +02:00
io: add AsyncReadExt::{chain, take} (#1484)
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![feature(async_await)]
|
||||
|
||||
use tokio_io::AsyncReadExt;
|
||||
use tokio_test::assert_ok;
|
||||
|
||||
#[tokio::test]
|
||||
async fn chain() {
|
||||
let mut buf = Vec::new();
|
||||
let rd1: &[u8] = b"hello ";
|
||||
let rd2: &[u8] = b"world";
|
||||
|
||||
let mut rd = rd1.chain(rd2);
|
||||
assert_ok!(rd.read_to_end(&mut buf).await);
|
||||
assert_eq!(buf, b"hello world");
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![feature(async_await)]
|
||||
|
||||
use tokio_io::AsyncReadExt;
|
||||
use tokio_test::assert_ok;
|
||||
|
||||
#[tokio::test]
|
||||
async fn take() {
|
||||
let mut buf = [0; 6];
|
||||
let rd: &[u8] = b"hello world";
|
||||
|
||||
let mut rd = rd.take(4);
|
||||
let n = assert_ok!(rd.read(&mut buf).await);
|
||||
assert_eq!(n, 4);
|
||||
assert_eq!(&buf, &b"hell\0\0"[..]);
|
||||
}
|
||||
Reference in New Issue
Block a user