This is more of a light musing than passionate appeal, so I won't be debating this vigorously, but I thought I'd offer it as a suggestion.
I learned closures and function literals through Scala, and compared to the Rust syntax, I appreciate the clarity of the Scala syntax provided by the separator between parameters and body.
val addFunc = (x: Int, y: Int) => x + y
An identical definition in Rust would be
let addFunc = |x: i32, y: i32| x + y
I like the use of =>
in Scala to separate the parameter declaration from the function body. I realize that this operator is already in use for match
, so a non-starter there, but I think there is an opportunity to use an unused operator such as ~>
in its place.
let addFunc = |x: i32, y: i32| ~> x + y
I suggest this because, even as someone who understands and recognizes the closure syntax, the current syntax looks like a run-on sentence; to me the |
doesn't sufficiently differentiate the parameters from the body and it looks like a single expression. The use of an arrow operator, to me, indicates that | THESE THINGS |
are doing ~> this() + stuff()
I also realize that ergonomics is an objective for Rust, but I think two characters is reasonable.
Finally, by making it optional, you avoid breaking changes, although I would be curious to see usage statistics down the road if implemented.
Anyway, just wanted to make a passing suggestion. I'm not a language expert or anything, so take this with a grain of salt.
Cheers