this post was submitted on 26 Jan 2023
8 points (100.0% liked)

Rust Programming

8126 readers
3 users here now

founded 5 years ago
MODERATORS
 

Did you know you can just whip out curly-braces all over the place in Rust and Go?

But why on Earth would you even want to do this?

top 4 comments
sorted by: hot top controversial new old
[–] Ephera@lemmy.ml 2 points 2 years ago* (last edited 2 years ago) (1 children)

Yeah, at work, we (regrettably) elected to use Kotlin for a project instead of previously Scala and those braces are definitely something I miss.

Kotlin does support basically the same thing with the run { } function, but Kotlin is so incredibly inconsistent with when implicit returns are allowed and when not, that it seems to confuse colleagues rather frequently...

[–] winnie@lemmy.ml 1 points 2 years ago* (last edited 2 years ago) (1 children)

I was also confused with explicit return in Kotlin, which behaves differently for inline and non inline functions.

[–] Ephera@lemmy.ml 1 points 2 years ago

Yeah, in inline functions, you have to use implicit returns, whereas in regular/named functions, you have to use explicit returns.

Although, there is yet another special case to that rule in that you can use labeled explicit returns in inline functions like so:

list.map { value ->
    return@map value*2
}
[–] developedby@lemmy.ml 2 points 2 years ago

Very useful for .borrow()ing things