trait Project { type Assoc; } pub struct FutResult(T); impl Project for FutResult { type Assoc = Result; } pub trait Stream { type Item; fn for_each(self, f: F) -> ForEach where F: FnMut(Self::Item) -> Fut, Self: Sized, { loop {} } } pub fn map(f: F) -> Map where F: FnMut(String) -> T, { loop {} } pub struct Map(F); pub trait FnOnce1 { type Output; } impl FnOnce1 for T where T: FnOnce(A) -> R, { type Output = R; } impl Stream for Map where F: FnOnce1, F::Output: Project, { type Item = ::Assoc; } pub struct ForEach { f: F, } fn main() { let bodies = map(|url| FutResult(Result::Ok(url))); bodies.for_each(|b| async { match b { Ok(Ok(url)) => {} Err(e) => {} Ok(Err(e)) => {} } }); }