Rust Language Cheat Sheet
11–20 of 65 posts
Re: Rust Language Cheat Sheet
#12I 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
#13As 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
#14I 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…
Re: Rust Language Cheat Sheet
#15Re: Rust Language Cheat Sheet
#16As 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?
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
#17I 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…
Re: Rust Language Cheat Sheet
#18Earlier 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.
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
#19As 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
#20As 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.
e.g. `let x = match y { ... };`