News for hackers. Stuff that matters.
Re:Rust 1.50 by trevor-e on Thursday February 11, 2021 @03:36PM (#26106775)
Can you also please explain what the "||" is doing? That looks really weird to me coming from Swift and don't see it in the docs.

edit: thanks all, should have known it was a lambda :D, in Swift we can omit this. My first thought seeing "||" was some type of OR logic since it's in the context of if/else

Re:Rust 1.50 by Sharlin on Thursday February 11, 2021 @03:52PM (#26106991)
Rust lambdas look like this:

    |ar,gs| expr
So `|| expr` is just a lambda function that takes no arguments and evaluates to `expr`.
Re:Rust 1.50 by varajelle on Thursday February 11, 2021 @03:52PM (#26106987)
It is a lambda function with no parameters.

The argument of then() is a function which is evaluated only if the bool is true.

Re:Rust 1.50 by laszlokorte on Thursday February 11, 2021 @03:53PM (#26107002)
empty parameter list of a closure.

rust: |x| x+x

swift: {x in x+x}

rust: || 42

swift: { 42 }