Rust's Block Pattern
notgull.net
Rust's Block Pattern
1–10 of 121 posts
Re: Rust's Block Pattern
#2I typically use closures to do this in other languages, but the syntax is always so cumbersome. You get the "dog balls" that Douglas Crockford always called them:
``` const config = (() => { const raw_data = ...
...
return compiled;
})()'const result = config.whatever;
// carry on
return result; ```
Really wish block were expressions in more languages.
Re: Rust's Block Pattern
#3Re: Rust's Block Pattern
#4It's idiomatic in Kotlin as well! https://kotlinlang.org/docs/scope-functions.html
Re: Rust's Block Pattern
#5The second example "erasure of mutability" makes more sense. But this effectively makes it a Rust-specific pattern.
Re: Rust's Block Pattern
#6https://doc.rust-lang.org/beta/unstable-book/language-featur...
Re: Rust's Block Pattern
#7It's idiomatic in Kotlin as well! https://kotlinlang.org/docs/scope-functions.html
Re: Rust's Block Pattern
#8let mut data = foo(); data.mutate(); let data = data;
May be preferable for short snippets where adding braces, the yielded expression, and indentation is more noise than it's worth.
Re: Rust's Block Pattern
#9It's used all throughout the Linux kernel and useful for macros.