Live data from Hacker News

Rust Language Cheat Sheet

cheats.rs

11–20 of 65 posts

Re: Rust Language Cheat Sheet

#11
I 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/

Re: Rust Language Cheat Sheet

#12
As 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?

Re: Rust Language Cheat Sheet

#13

As 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?

They 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.

Re: Rust Language Cheat Sheet

#14

I 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…

Oh, 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! :)

Re: Rust Language Cheat Sheet

#16

As 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?

Every 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.)

Re: Rust Language Cheat Sheet

#17

I 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…

Yes, 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/

Re: Rust Language Cheat Sheet

#18
post #5

Earlier quoted context omitted.

Smalltalk. 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.pn... (the example doesn't feature primitives calls, not because they don't fit — a primitive call would be — but because their use case is extremely specific to implementing a system).

Scheme has to fall somewhere between Smalltalk and Forth for quantity of syntax too. To me, these are the prettiest languages.

I 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.

Re: Rust Language Cheat Sheet

#19

As 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?

As others have said the principal is: no semicolons after things that use {}, semicolons after everything else.

Re: Rust Language Cheat Sheet

#20
post #19

As 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?

As others have said the principal is: no semicolons after things that use {}, semicolons after everything else.

This isn't quite true. Semi-colons are required after all expressions in rust (even when braces are present).

e.g. `let x = match y { ... };`

Post reply on HN