...
"This solution is also similar to other languages’ features or conventions"
As far as I know, in Rust you can't use "_" for that, as the value will be dropped right away, so the mutex/resource/etc. won't live for the scope.
...
"This solution is also similar to other languages’ features or conventions"
As far as I know, in Rust you can't use "_" for that, as the value will be dropped right away, so the mutex/resource/etc. won't live for the scope.
https://rust.godbolt.org/z/P1z7YeP4Y
As you see, Rust specifically rejects this code because it's never what you meant, either write explicitly "I want to take and then immediately give away the lock" via drop(LOCK.lock()) (this really might be what you wanted, the Linux kernel does this in a few places) or write an actual named placeholder variable like in my third example function.
> rebind a variable in the same scope
But only re-assigning values of the same type. Otherwise:
int x = foo();
int x = bar();
error: redefinition of 'x'
and, int x = foo();
long x = bar();
error: redefinition of 'x'
What are you talking about? let x = foo()
let x = bar()
Regardless of the return types. That obviates a lot of the motivating problem that the c++ paper is contorting itself to fixYeah, it's the same in c#. This is noticeable when in the same scope you can have multlple "_" vars. If these were actual names, they would be a name clash.
One of the uses is take some parts of a tuple return and ignore the others.
e.g.
var (thingIwant, _, _, _) = FunctionThaReturnsATupleOfFourThings();
There are three "_" in that expression, and they are different vars with different types. They don't really have the same name, they don't have names at all.