Skip to content

Comment on Resource efficient Thread Pools with Zigparent

Comments

The thing that really surprised me about Rust is the significance of a semicolon at the end of a function body. E.g.:

    fn foo { 1; }
Returns unit while
    fn foo { 1 }
Returns 1. This reminds me of nothing so much as the infamous JavaScript ASI footgun where this returns undefined:
    function foo() {
      return
      2;
    }

It's not just the function's body, it's any block. Blocks in rust are expressions and return their last statement's value. It's nothing like Javascript's ASI where it's just inserting ; implicitly and only `return` can return a value.

It's also nothing like Javascript because Rust is statically typed. If you accidentally insert a semi-colon (or not), you're almost guaranteed to get a compile error.

The second function is a syntax error since you are not declaring the return value in the function signature.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.