From 40cefb2ff08d0e872408c8218b5d4d22d2c5ba11 Mon Sep 17 00:00:00 2001
From: Akshay ?
s in place of return types. Let’s try to fix that
A function cannot access it’s environment. Our solution will not work. add_curried3
attempts to access x
, which is not allowed! A closure1 however, can. If we are returning a closure, our return type must be impl Fn
, and not fn
. The difference between the Fn
trait and function pointers is beyond the scope of this post.
Armed with knowledge, we refine our expected output, this time, employing closures:
-fn add(x: u32) -> impl Fn(u32) -> impl Fn(u32) -> u32 {
- return move |y| move |z| x + y + z;
-}
+
Alas, that does not compile either! It errors out with the following message:
error[E0562]: `impl Trait` not allowed outside of function
and inherent method return types
@@ -500,7 +500,7 @@ test tests::works ... ok
https://peppe.rs/posts/auto-currying_rust_functions/
-?
s in place of return types. Let’s try to fix that
A function cannot access it’s environment. Our solution will not work. add_curried3
attempts to access x
, which is not allowed! A closure1 however, can. If we are returning a closure, our return type must be impl Fn
, and not fn
. The difference between the Fn
trait and function pointers is beyond the scope of this post.
Armed with knowledge, we refine our expected output, this time, employing closures:
-fn add(x: u32) -> impl Fn(u32) -> impl Fn(u32) -> u32 {
- return move |y| move |z| x + y + z;
-}
+
Alas, that does not compile either! It errors out with the following message:
error[E0562]: `impl Trait` not allowed outside of function
and inherent method return types
--
cgit v1.2.3