Skip to content

Commit

Permalink
examplar use of Peekable::peek
Browse files Browse the repository at this point in the history
  • Loading branch information
dingxiangfei2009 committed Jan 8, 2020
1 parent e5c60ad commit f753463
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions futures/tests/stream_peekable.rs
@@ -0,0 +1,13 @@
use futures::executor::block_on;
use futures::pin_mut;
use futures::stream::{self, Peekable, StreamExt};

#[test]
fn peekable() {
block_on(async {
let peekable: Peekable<_> = stream::iter(vec![1u8, 2, 3]).peekable();
pin_mut!(peekable);
assert_eq!(peekable.as_mut().peek().await, Some(&1u8));
assert_eq!(peekable.collect::<Vec<u8>>().await, vec![1, 2, 3]);
});
}

0 comments on commit f753463

Please sign in to comment.