mirror of
https://github.com/async-rs/async-std.git
synced 2025-04-09 09:56:42 +00:00
commit
6f4dcad6a0
2 changed files with 18 additions and 13 deletions
|
@ -105,9 +105,10 @@ pub trait DoubleEndedStream: Stream {
|
||||||
```
|
```
|
||||||
# fn main() { async_std::task::block_on(async {
|
# fn main() { async_std::task::block_on(async {
|
||||||
#
|
#
|
||||||
use async_std::stream::double_ended_stream::{self, DoubleEndedStream};
|
use async_std::prelude::*;
|
||||||
|
use async_std::stream;
|
||||||
|
|
||||||
let mut s = double_ended_stream::from_iter(vec![7u8]);
|
let mut s = stream::from_iter(vec![7u8]);
|
||||||
|
|
||||||
assert_eq!(s.next_back().await, Some(7));
|
assert_eq!(s.next_back().await, Some(7));
|
||||||
assert_eq!(s.next_back().await, None);
|
assert_eq!(s.next_back().await, None);
|
||||||
|
@ -132,9 +133,10 @@ pub trait DoubleEndedStream: Stream {
|
||||||
```
|
```
|
||||||
# fn main() { async_std::task::block_on(async {
|
# fn main() { async_std::task::block_on(async {
|
||||||
#
|
#
|
||||||
use async_std::stream::double_ended_stream::{self, DoubleEndedStream};
|
use async_std::prelude::*;
|
||||||
|
use async_std::stream;
|
||||||
|
|
||||||
let mut s = double_ended_stream::from_iter(vec![1u8, 2, 3, 4, 5]);
|
let mut s = stream::from_iter(vec![1u8, 2, 3, 4, 5]);
|
||||||
|
|
||||||
let second = s.nth_back(1).await;
|
let second = s.nth_back(1).await;
|
||||||
assert_eq!(second, Some(4));
|
assert_eq!(second, Some(4));
|
||||||
|
@ -159,9 +161,10 @@ pub trait DoubleEndedStream: Stream {
|
||||||
```
|
```
|
||||||
# fn main() { async_std::task::block_on(async {
|
# fn main() { async_std::task::block_on(async {
|
||||||
#
|
#
|
||||||
use async_std::stream::double_ended_stream::{self, DoubleEndedStream};
|
use async_std::prelude::*;
|
||||||
|
use async_std::stream;
|
||||||
|
|
||||||
let mut s = double_ended_stream::from_iter(vec![1u8, 2, 3, 4, 5]);
|
let mut s = stream::from_iter(vec![1u8, 2, 3, 4, 5]);
|
||||||
|
|
||||||
let second = s.rfind(|v| v % 2 == 0).await;
|
let second = s.rfind(|v| v % 2 == 0).await;
|
||||||
assert_eq!(second, Some(4));
|
assert_eq!(second, Some(4));
|
||||||
|
@ -185,9 +188,10 @@ pub trait DoubleEndedStream: Stream {
|
||||||
```
|
```
|
||||||
# fn main() { async_std::task::block_on(async {
|
# fn main() { async_std::task::block_on(async {
|
||||||
#
|
#
|
||||||
use async_std::stream::double_ended_stream::{self, DoubleEndedStream};
|
use async_std::prelude::*;
|
||||||
|
use async_std::stream;
|
||||||
|
|
||||||
let s = double_ended_stream::from_iter(vec![1u8, 2, 3, 4, 5]);
|
let s = stream::from_iter(vec![1u8, 2, 3, 4, 5]);
|
||||||
|
|
||||||
let second = s.rfold(0, |acc, v| v + acc).await;
|
let second = s.rfold(0, |acc, v| v + acc).await;
|
||||||
|
|
||||||
|
@ -215,9 +219,10 @@ pub trait DoubleEndedStream: Stream {
|
||||||
```
|
```
|
||||||
# fn main() { async_std::task::block_on(async {
|
# fn main() { async_std::task::block_on(async {
|
||||||
#
|
#
|
||||||
use async_std::stream::double_ended_stream::{self, DoubleEndedStream};
|
use async_std::prelude::*;
|
||||||
|
use async_std::stream;
|
||||||
|
|
||||||
let s = double_ended_stream::from_iter(vec![1u8, 2, 3, 4, 5]);
|
let s = stream::from_iter(vec![1u8, 2, 3, 4, 5]);
|
||||||
let sum = s.try_rfold(0, |acc, v| {
|
let sum = s.try_rfold(0, |acc, v| {
|
||||||
if (acc+v) % 2 == 1 {
|
if (acc+v) % 2 == 1 {
|
||||||
Ok(v+3)
|
Ok(v+3)
|
||||||
|
|
|
@ -587,13 +587,13 @@ extension_trait! {
|
||||||
|
|
||||||
assert_eq!(s.next().await, Some(1));
|
assert_eq!(s.next().await, Some(1));
|
||||||
// There will be no delay after the first time.
|
// There will be no delay after the first time.
|
||||||
assert!(start.elapsed().as_millis() <= 210);
|
assert!(start.elapsed().as_millis() < 400);
|
||||||
|
|
||||||
assert_eq!(s.next().await, Some(2));
|
assert_eq!(s.next().await, Some(2));
|
||||||
assert!(start.elapsed().as_millis() <= 210);
|
assert!(start.elapsed().as_millis() < 400);
|
||||||
|
|
||||||
assert_eq!(s.next().await, None);
|
assert_eq!(s.next().await, None);
|
||||||
assert!(start.elapsed().as_millis() <= 210);
|
assert!(start.elapsed().as_millis() < 400);
|
||||||
#
|
#
|
||||||
# }) }
|
# }) }
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in a new issue