8 ms·
Rust Language Cheat Sheet
- shmerl 7y agoVery nice!
- rrss 7y agoAnyone remember when rust had ~ and @?
- spencerwgreene 7y agoIf you had an equivalent Cheat Sheet for other programming languages (no programs or opinions), which language would look best?
- masklinn 7y agoSmalltalk. Or Forth. This cheatsheet is syntactic, both have very little syntax. You can famously exercise all of Smalltalk's syntax on half a postcard: https://miro.medium.com/max/1000/1*Aa0AEoUgjZov8yrgdplsIg.png https://miro.medium.com/max/1000/1*Aa0AEoUgjZov8yrgdplsIg.pn... (the example doesn't feature primitives calls, not because they don't fit — a primitive call would be <primitive: xxx> — but because their use case is extremely specific to implementing a system).
- excessive 7y agoScheme has to fall somewhere between Smalltalk and Forth for quantity of syntax too. To me, these are the prettiest languages.
- masklinn 7y agoI didn't mention lisps because I'm never sure how to classify "built-in" special forms: should they be considered normal names and thus omitted from a syntactic overview or should they be considered keywords and included? On the one hand they usually have non-normal evaluation and custom mini-languages, on the other so do most macros otherwise you'd just use a function. But yeah, these are the sort of languages I think of as "simple": small languages which reach "smallness" by giving access to a limited set of extremely powerful constructs.
- excessive 7y agoYes, and I'm not sure the R*RS standards even specify which special forms are fundamental vs implemented by macros. However, Smalltalk has some keywords too. In any case, it could be a concise cheat sheet.
- masklinn 7y ago> However, Smalltalk has some keywords too. Indeed but they're all on the postcard above (true, false, nil, super and self). Smalltalk's closest thing to built-in special forms would be primitives but they have a generic "shape" and they're pretty much always used as implementation details for the "normal" messages which system users interact with.
- arnsholt 7y ago> small languages which reach "smallness" by giving access to a limited set of extremely powerful constructs That's one of the things I really loved when working in Smalltalk: the language gives you all of the building blocks necessary to build more or less then entire standard library, which makes it extremely simple to implement custom control structures for your application. That, and the fact that you're programming directly in your running application of course.
- tiffanyh 7y agoCheck out https://learnxinyminutes.com/ https://learnxinyminutes.com/
- joelfolksy 7y agobrainfuck or another esoteric language.
- nmca 7y agoThe explanation of lifetimes linked here is really great - I think this goes a little further than just a cheat sheet. Seems to be more like excellent Clif notes.
- alexbanks 7y agoLifetimes are about where I bowed out of Rust. I haven't worked with C++ before, or really ever thought about borrowing or lifetimes, so it never really clicked in my head. What's worse is the Rust community's desire to remind you to "Just read the book". Maybe this would be a worthwhile read to get back into it?
- Myrmornis 7y agoThe Book by Steve Klabnik looks fantastic for newer programmers, but as an experienced programmer I did find it difficult to get into. On the other hand, the O’Reilly book by Jim Blandy and Jason Orendorff is just amazing for experienced programmers (and would be unsuitable for new programmers). It’s the best programming language book I’ve ever read. It’s great that both books exist, filling those two niches.
- fold_left 7y agoRalf Biedert, thanks so much for this! I've been learning Rust via the Rust Book for the past few months and this will help so, so much - fantastic work.
- quietbritishjim 7y agoI know everyone says how good Rust's documentation is but I tried learning Rust with The Rust Book and found it frustrating: too long and wordy on the easy bits and without useful insight on the hard bits. I ended up buying Programming Rust by Jim Blandy [0] on a recommendation from HN comments and found it must easier to learn from. I'm already familiar with several other languages, which that book assumes, so your milage may vary. [0] https://www.amazon.co.uk/Programming-Rust-Jim-Blandy/dp/1491927283 https://www.amazon.co.uk/Programming-Rust-Jim-Blandy/dp/1491...
- indemnity 7y agoYou’re not alone. I found the Rust book very hard going, whereas Programming Rust was just the right amount of rigor and interesting examples for me.
- steveklabnik 7y agoThis is why I'm glad we have both; I don't think one resource could ever satisfy everyone. Pumped to see Rust in Action getting closer to publication too!
- AlchemistCamp 7y agoI just bought Rust in Action a couple weeks ago (after having gone up to chapter 11 in the No Starch book). It's definitely good to have both. I'll probably do 1/2 the new book, finish the 1st one and then finish the new one. I did pretty much the same thing with Dave Thomas's Programming Elixir book, bailing halfway through, using a 2nd resource to consolidate, and then returning to finish it. I like learning Rust so far. The main thing I wonder is what kinds of projects are good to do while learning. I went from Node to Rails to Phoenix and normally I just rewrite web apps I've previously created in the language I'm learning. With Rust, it feels like I should build something different, something lower-level like a tool, an emulator or a 2D game.
- ammaskartik 7y agoThis is great. Nice work!
- spectramax 7y agoI love the design of this site. It is compact, dense and to the point. I think we need to port cheatsheets for most popular languages in this format. There is also Learn Y in X minutes[1] which I often refer to but a cheatsheet like this where everything is neatly organized would be a huge help. I jump between 3-4 languages everyday and it is a pain in the ass to Google syntax, frankly embarrassing that I have to. [1] https://learnxinyminutes.com/ https://learnxinyminutes.com/
- ExtremisAndy 7y agoOh, my! I have spend countless hours on the web looking for (and successfully finding, of course) cheat sheets for all sorts of languages, but somehow I had never come across this site. This is extremely well done. Thank you,spectramax, for basically revolutionizing my life this morning! :)
- andrewl-hn 7y agoSurprisingly, https://learnxinyminutes.com/docs/bash/ https://learnxinyminutes.com/docs/bash/ is the best resource out there to learn shell scripting. This page basically turned me from a novice who could only write two commands with | or && between them to a competent shell programmer. My shell scripts have functions, descriptive variables, error handling, good formatting, etc.
- dzamlo 7y agoI find shellcheck to be really great to go to the step beyound. It find a lot of things that make most shell script brittle and teach you some best practice. Add shfmt on top and you are good to go.
- laGrenouille 7y agoYes, agreed. The site is great and it would be nice to have a similar design for other languages. The closest example that I frequently use is cppreference[1] for C and C++, languages that I use just infrequently enough to forget the basic syntax. [1] https://en.cppreference.com/ https://en.cppreference.com/
- ridiculous_fish 7y agoAs a Rust noob, what's the rhyme or reason for semicolons? I see the example: struct S {} but here the semicolon is required: type T = S; or you get weird errors. It's hard to predict when a semicolon is required at least for type declarations, is there an underlying principle?
- kchamplewski 7y agoThey appear to be similar to the way most other languages like C and Java use semicolons, where a semicolon isn't required after a code block (generally denoted by squiggly brackets), but is required at the end of most (all?) other statements.
- Sharlin 7y agoThe most confusing thing ever is, of course, the fact that C struct/union and C++ class declarations do require a semicolon after the closing curly bracket. This is because type declarations are permitted to occur inline in certain contexts, notably as the type specifier in a variable declaration.
- lifthrasiir 7y agoEvery language item ends either with blocks (when a nested structure is required) or `;` (when it's not). They do not mix; if an item uses a block you don't need `;`. So `type` needs no more blocks and ends with `;`, while `struct S { ... }` doesn't need `;`. Completing an example, there is another form of `struct` that looks like `struct S(u32);` which do need `;` by the aforementioned logic. (The same logic applies to statements. You may think of an apparent exception like `{ println!("42"); 54 }`, but here `54` is an expression and you can't put a non-expression statement like `let x = 42` there without a semicolon.)
- dbaupp 7y agoAs others have said the principal is: no semicolons after things that use {}, semicolons after everything else.
- 7y ago
- known 7y agohttps://archive.is/utKnz https://archive.is/utKnz
- xrio 7y agoAuthor here. Thank you all for your comments, issues and pull requests. You are amazing!
- cswiercz 7y agoGreat quick reference, but a wasted opportunity to call the site “cheate.rs”.
- RedHotRiplets 7y agoAny plans on adding Box, Rc, RefCell, and the differences thereof? That's the thing that trips me up the most right now.
- steveklabnik 7y agoTo give you a quick summary: Box is (mostly) used in two specific circumstances: when you want to have ownership of something that lives longer than a single function, and to create heterogeneous lists of things (a "trait object"). Rc is used when you need multiple ownership of something, and you're not going to be sharing those things between threads. RefCell is a type that moves the borrow checker to runtime; it's useful when you're trying to mutate something, and Rust's static checking can't tell that it's okay. If you mess it up, you'll get a panic. This often happens in combination with Rc, since Rc makes something have multiple owners.
- vvanders 7y agoPretty solid list, only thing I saw missing was binary representation for literals("0b0000_1000") which is really handy when working with micros or other things that use a lot of flags or bits.
- saagarjha 7y agoReally enjoyed the fact that there was an "Idiomatic Rust" section.
- wuxb 7y agoJust to be funny, it's a Cheatbook.
- ohazi 7y ago> unsafe {} > If you need to crash your code in production heh :-)
- legulere 7y agoThe first ' in '' is red and the second one is black. Does the syntax highlighter maybe work on ucs-16 characters wrongly?