Created
July 29, 2017 20:29
-
-
Save alexcrichton/16cb7dca2902cd0bf1776616ff63e192 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let b = mk::< | |
Forward< | |
Iter<std::vec::IntoIter<Result<i32, _>>>, | |
Box<Sink<SinkItem = i32, SinkError = u32>>, | |
>, | |
>(); | |
let c = b.map_err(|_: u32| mk()); | |
c.join(mk::<Box<Future<Item = (), Error = ()>>>()); | |
} | |
fn mk<T>() -> T { | |
loop {} | |
} | |
struct Iter<I> { | |
_iter: I, | |
} | |
impl<I, T, E> Stream for Iter<I> | |
where | |
I: Iterator<Item = Result<T, E>>, | |
{ | |
type Item = T; | |
type Error = E; | |
} | |
struct Forward<T: Stream, U> { | |
_a: (T, U), | |
} | |
impl<T, U> Future for Forward<T, U> | |
where | |
U: Sink, | |
T: Stream, | |
T::Error: From<U::SinkError>, | |
{ | |
type Item = (T, U); | |
type Error = T::Error; | |
} | |
trait Future { | |
type Item; | |
type Error; | |
fn map_err<F, E>(self, _: F) -> MapErr<Self, F> | |
where | |
F: FnOnce(Self::Error) -> E, | |
Self: Sized, | |
{ | |
loop {} | |
} | |
fn join<B>(self, _: B) -> Join<Self, B::Future> | |
where | |
B: IntoFuture<Error = Self::Error>, | |
Self: Sized, | |
{ | |
loop {} | |
} | |
} | |
impl<S: ?Sized + Future> Future for Box<S> { | |
type Item = S::Item; | |
type Error = S::Error; | |
} | |
struct Join<A, B> | |
where | |
A: Future, | |
{ | |
_a: MaybeDone<A>, | |
_b: B, | |
} | |
enum MaybeDone<A: Future> { | |
_Done(A::Item), | |
} | |
struct MapErr<A, F> { | |
_a: (A, F), | |
} | |
impl<U, A, F> Future for MapErr<A, F> | |
where | |
A: Future, | |
F: FnOnce(A::Error) -> U, | |
{ | |
type Item = A::Item; | |
type Error = U; | |
} | |
trait IntoFuture { | |
type Future: Future; | |
type Item; | |
type Error; | |
} | |
impl<F: Future> IntoFuture for F { | |
type Future = F; | |
type Item = F::Item; | |
type Error = F::Error; | |
} | |
trait Sink { | |
type SinkItem; | |
type SinkError; | |
} | |
impl<S: ?Sized + Sink> Sink for Box<S> { | |
type SinkItem = S::SinkItem; | |
type SinkError = S::SinkError; | |
} | |
trait Stream { | |
type Item; | |
type Error; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment