Live data from Hacker News

Idiomatic Rust

a-i-nstein.neocities.org

21–30 of 45 posts

Re: Idiomatic Rust

#21
post #7

Hello HN, I've recently started learning Rust, and I'm finding it incredibly interesting! However, I'm also encountering a wealth of new syntax, built-in functions, and concepts that are unique to Rust. To solidify my understanding and create a useful resource for myself (and hopefully others), I've been diligently documenting these discoveries. I've decided to share these insights by starting a blog, where I'll delv…

If you think any of the features you listed are unique to Rust, you need to learn more languages.

[flagged]

Re: Idiomatic Rust

#25
Please do Strings next. Effective Rust isn't useful at guiding to a good default.

The technical arguments for one or the other option are available in a bunch of places, but no good guidance on an idiomatic default.

Re: Idiomatic Rust

#26
How it renders on mobile:

  Rust
  simplifies
  numerical
  variable
  initialization
  by
  allowing
  type
  annotation
  directly
  within
  the
  value
  assignment.

Re: Idiomatic Rust

#27
post #19
post #11

Is x = 57u8 actually idiomatic when compared to x: u8 = 57? I don't remember any Rust resource using that.

It's not only not really idiomatic, it's almost never necessary in practice. I was struggling to think of a time I'd ever given a type annotation to an integer local variable - because normally the place the variable ends up dictates the type. Local variable becomes part of struct? Struct dictates type. Passed into function? Function dictates type. Multiplied by other variable and then that is passed to function? The…

It can be necessary if you’re passing it to a generic type/function.

Re: Idiomatic Rust

#28
post #25

Please do Strings next. Effective Rust isn't useful at guiding to a good default. The technical arguments for one or the other option are available in a bunch of places, but no good guidance on an idiomatic default.

Can you give an example of a situation where you’re not sure what string type to use?

Re: Idiomatic Rust

#29

The "Effective Rust" book was recently published and can be read online, for free [1]. I'd go as far and say that all of it is, by definition, idiomatic. I guess I'm saying, you could reasonably change the book's title to "Idiomatic Rust". I'd read that first and then look into what bits it doesn't cover. That could be worth a blog like the one this is about. [1] https://www.lurklurk.org/effective-rust/

Thanks. I'll check it out.
Post reply on HN