Sometimes I have a complex series of expressions that I need to perform to initialize a variable.
In JS we can use the do expressions proposal, which looks like this:
In Rust we don't need special syntax support because Rust has block expressions built-in. In this case we clone a
PathBuf, pop the last segment off, push a new
".tmp" segment on, and then return the dir value.
Note that in both the do expression and the block expression cases we isolate the complex expressions into another scope. This allows us to declare variables and generally isolate initialization logic from the rest of the program and make it more clear that we aren't using those temporary variables in the rest of the program. In JS this allows us to use const and in Rust it allows us to remove the mutability requirement on our variable.