feat(chunk): implement Extend and IntoIterator for Chunk

The real reason to provide these implementations is so that `concat` on
the `Body` can work to easily join all the chunks into 1.
This commit is contained in:
Sean McArthur
2017-04-08 17:16:08 -07:00
parent 5c1cfa2bce
commit 78512bdb18
2 changed files with 70 additions and 1 deletions

View File

@@ -96,3 +96,18 @@ fn _assert_send_sync() {
_assert_send::<Chunk>();
_assert_sync::<Chunk>();
}
#[test]
fn test_body_stream_concat() {
use futures::{Sink, Stream, Future};
let (tx, body) = Body::pair();
::std::thread::spawn(move || {
let tx = tx.send(Ok("hello ".into())).wait().unwrap();
tx.send(Ok("world".into())).wait().unwrap();
});
let total = body.concat().wait().unwrap();
assert_eq!(total.as_ref(), b"hello world");
}