]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/run-pass/issues/issue-40003.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
17 let rx
= Err
::<Vec
<usize>, u32>(1).into_future();
19 rx
.map(|l
: Vec
<usize>| stream
::iter(l
.into_iter().map(|i
| Ok(i
))))
25 use future
::{Future, IntoFuture}
;
35 fn map
<F
, U
>(self, _
: F
) -> Map
<Self, F
>
36 where F
: FnOnce(Self::Item
) -> U
,
42 fn flatten_stream(self) -> FlattenStream
<Self>
43 where <Self as Future
>::Item
: stream
::Stream
<Error
=Self::Error
>,
50 pub trait IntoFuture
{
51 type Future
: Future
<Item
=Self::Item
, Error
=Self::Error
>;
54 fn into_future(self) -> Self::Future
;
57 impl<F
: Future
> IntoFuture
for F
{
60 type Error
= F
::Error
;
62 fn into_future(self) -> F
{
67 impl<T
, E
> IntoFuture
for result
::Result
<T
, E
> {
68 type Future
= FutureResult
<T
, E
>;
72 fn into_future(self) -> FutureResult
<T
, E
> {
77 pub struct Map
<A
, F
> {
81 impl<U
, A
, F
> Future
for Map
<A
, F
>
83 F
: FnOnce(A
::Item
) -> U
,
86 type Error
= A
::Error
;
89 pub struct FlattenStream
<F
> {
93 impl<F
> Stream
for FlattenStream
<F
>
95 <F
as Future
>::Item
: Stream
<Error
=F
::Error
>,
97 type Item
= <F
::Item
as Stream
>::Item
;
98 type Error
= <F
::Item
as Stream
>::Error
;
101 pub struct FutureResult
<T
, E
> {
105 impl<T
, E
> Future
for FutureResult
<T
, E
> {
118 fn buffer_unordered(self, amt
: usize) -> BufferUnordered
<Self>
119 where Self::Item
: IntoFuture
<Error
= <Self as Stream
>::Error
>,
125 fn chunks(self, _capacity
: usize) -> Chunks
<Self>
132 pub struct IterStream
<I
> {
136 pub fn iter
<J
, T
, E
>(_
: J
) -> IterStream
<J
::IntoIter
>
137 where J
: IntoIterator
<Item
=Result
<T
, E
>>,
142 impl<I
, T
, E
> Stream
for IterStream
<I
>
143 where I
: Iterator
<Item
=Result
<T
, E
>>,
149 pub struct Chunks
<S
> {
153 impl<S
> Stream
for Chunks
<S
>
156 type Item
= Result
<Vec
<<S
as Stream
>::Item
>, u32>;
157 type Error
= <S
as Stream
>::Error
;
160 pub struct BufferUnordered
<S
> {
169 fn new
<S
>(_s
: S
, _amt
: usize) -> BufferUnordered
<S
>
171 S
::Item
: IntoFuture
<Error
=<S
as Stream
>::Error
>,
174 Slot
::Next
::<<S
::Item
as IntoFuture
>::Future
>(1)
175 }).collect
::<Vec
<_
>>();
179 impl<S
> Stream
for BufferUnordered
<S
>
181 S
::Item
: IntoFuture
<Error
=<S
as Stream
>::Error
>,
183 type Item
= <S
::Item
as IntoFuture
>::Item
;
184 type Error
= <S
as Stream
>::Error
;