diff --git a/practice/unreferenced_types_in_rust/src/bin/8_solution_ultimate.rs b/practice/unreferenced_types_in_rust/src/bin/8_solution_ultimate.rs new file mode 100644 index 0000000..4f25b6b --- /dev/null +++ b/practice/unreferenced_types_in_rust/src/bin/8_solution_ultimate.rs @@ -0,0 +1,28 @@ +fn main() {} + +trait Trait1 { + type Item; + type T1: core::iter::Iterator; + fn f1() -> Self::T1; +} + +struct Once1 {} + +impl Trait1 for Once1 { + type Item = i32; + type T1 = core::iter::Once; + fn f1() -> Self::T1 { + core::iter::once(13_i32) + } +} + +struct Map1 {} + +impl Trait1 for Map1 { + type Item = i32; + type T1 = core::iter::Map, &'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)) + } +}