Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions practice/unreferenced_types_in_rust/src/bin/8_solution_ultimate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
fn main() {}

trait Trait1 {
type Item;
type T1: core::iter::Iterator<Item = Self::Item>;
fn f1() -> Self::T1;
}

struct Once1 {}

impl Trait1 for Once1 {
type Item = i32;
type T1 = core::iter::Once<Self::Item>;
fn f1() -> Self::T1 {
core::iter::once(13_i32)
}
}

struct Map1 {}

impl Trait1 for Map1 {
type Item = i32;
type T1 = core::iter::Map<core::iter::Once<Self::Item>, &'static dyn Fn(i32) -> i32>;
fn f1() -> Self::T1 {
// Just put the existential type behind the &dyn and you're ready to go =)
core::iter::once(13_i32).map(&(|e| e + 10))
}
}