6 ms·
Idiomatic Rust
- astennumero 2y agoHello 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 delve into the idiomatic Rust behaviors I'm learning. I've already compiled a substantial collection of examples and plan to discuss them in detail. My goal is to maintain a regular posting schedule, reflecting my ongoing learning journey. I'd love to hear your thoughts on this project. Additionally, I'm eager to learn about your favorite idiomatic Rust patterns. If you have any specific behaviors or concepts you'd like to see covered in my blog, please share them! Thanks in advance for your feedback and suggestions.
- johnisgood 2y agoRight now there is only Part 1, right? If not, this will need fixing. I tried clicking on "Show Me!" just in case it loads more, but it did not. As someone else said, I would like to see a TOC instead, personally.
- astennumero 2y agoAh, thanks for highlighting that UX flow. I'll soon have a ToC once I have enough content.
- xigoi 2y agoIf you think any of the features you listed are unique to Rust, you need to learn more languages.
- broneedsjob 2y ago[flagged]
- astennumero 2y agoCheck out Part 2: https://a-i-nstein.neocities.org/pages/part-2 https://a-i-nstein.neocities.org/pages/part-2 I hope some of these are unique to Rust. Let me know!
- xigoi 2y agoEh, not at all.
- tyilo 2y ago> Idiomatic Rust Not very idiomatic to not use the builtin code formatter...
- broneedsjob 2y ago[flagged]
- astennumero 2y agoI'm new to this blogging environment. What do you mean? The HTML's built in formatter? I actually wanted to have these examples ready to be used anywhere else and that's why I chose github gists.
- keyle 2y agoPersonally, I'd prefer to see a table of content and jump through it than being taken through it like a little story. Is there anything more than part 1?
- devsda 2y agoYeah, I clicked the "Show me" half expecting a popup asking to subscribe to a newsletter for "updates" on more parts. OP, this is just feedback and I hope that you'll continue documenting your rust journey even if it's just for yourself.
- astennumero 2y agoHmm. That's an interesting UX feedback. I'm new to Rust and wanted to highlight it as a disclaimer. That's the reason behind the the home page, the disclaimer box and the show me button. I'll see if there's a better to do it. Thanks.
- astennumero 2y agoYes sir. Part 2 just dropped. Here - https://a-i-nstein.neocities.org/pages/part-2 https://a-i-nstein.neocities.org/pages/part-2. About the ToC, I agree. I'm planning to build a table of content once I have enough content.
- ForTheKidz 2y agoPage is mostly margin on safari mobile fyi
- globnomulous 2y agoAlmost entirely margin on Firefox Mobile as well.
- astennumero 2y agoThanks for letting me know. Just fixed it.
- wegfawefgawefg 2y agoonly one part. applies to zero of the rust code i write. formats horrendously on mobile. you gotta work on this more before putting it on hacker news
- ahoka 2y agoThis is why AI answers suck, lot of bad advice on the internet.
- astennumero 2y agoYup. I've fixed it now. Thanks!
- AbuAssar 2y agovery low effort, I expected more high quality content from HN front page
- serial_dev 2y agoMaybe I’m missing something because the mobile version is unreadable, but it’s basically one short page with like 3 sections of how to work with ints??
- Hamuko 2y agoIs x = 57u8 actually idiomatic when compared to x: u8 = 57? I don't remember any Rust resource using that.
- School-Cotton 2y agoIt doesn’t really make a difference imo.
- leoedin 2y agoIt'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 type is determined by the function.
- School-Cotton 2y agoIt can be necessary if you’re passing it to a generic type/function.
- serial_dev 2y agoSame, I don’t think that’s idiomatic at all
- broneedsjob 2y ago[flagged]
- asimpletune 2y agoHey I enjoyed reading part 1. Would you add a media query though to the left and right margins? It’s impossible to read vertically on mobile.
- astennumero 2y agoThank you! Glad you enjoyed. I've fixed that mobile issue.
- amalive 2y agoDon't be let down by other comments. The topic itself something I think people would more enjoy when it is more comprehensive. Add more content with your findings, refine and then post again on HN
- broneedsjob 2y ago[flagged]
- astennumero 2y agoThank you. I'm glad you think that someone will find this useful.
- virtualritz 2y agoThe "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/ https://www.lurklurk.org/effective-rust/
- astennumero 2y agoThanks. I'll check it out.
- jbhn 2y agoPlease 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.
- astennumero 2y agoSure. I'll add it to my bucket list.
- School-Cotton 2y agoCan you give an example of a situation where you’re not sure what string type to use?
- jbhn 2y agoI think Library APIs are a good example. I've found myself in the situation where I do not care about the string representation (or can convert in a few places if necessary), but need to provide an interface for others that is as frictionless as possible. My instinct there was to be generic and use From/To traits, but it never felt quite right.
- sshine 2y agoHow it renders on mobile: Rust simplifies numerical variable initialization by allowing type annotation directly within the value assignment.
- astennumero 2y agoThanks and apologies. Fixed it!
- astennumero 2y agoThank you everyone for your feedback. Part 2 is now available here: https://a-i-nstein.neocities.org/pages/part-2 https://a-i-nstein.neocities.org/pages/part-2. I've addressed the mobile viewing issue. I'll also be working on adding a Table of Contents. As I'm new to Rust and unfamiliar with unconventional programming paradigms, I understand that some of the concepts I'm exploring may not be idiomatic for experienced programmers. My hope is that this series offers something new to everyone, and I'd be happy if it introduces even just one new concept to someone. That would be my contribution to the community.
- LandR 2y ago> unconventional programming paradigms What parts in this article do you think are unconventional?
- astennumero 2y agoAlso can someone explain what the [flagged] in the title means?