1 hour ago · 7 min read1423 words · Tech · 0 comments

IntroductionThere is an RFC open on Rust which proposes what I’m calling hoisting expressions into the language. These are expressions which can be introduced inside of closures-only (for now), and are hoisted by the compiler to run before the rest of the closure does. To illustrate how they work, consider this example: rustprint!("hello "); hoist { print!("world!") };CopyEven though in the code we declared "hello " first and "world!" second, this will print: world!hello . In a way, you can think of hoist as the inverse of defer: defer in languages declare statements which are run after exiting the scope. hoist in Rust would declare expressions which are run before entering the scope. If you’re familiar with variable hoisting from JavaScript: this feature goes beyond that, not just hoisting variable (var) declarations to the top of the function, but hoisting the entire expression-evaluation to run before the rest of the closure. The proposal does not call it hoistRFC 3968 proposes the…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.