Skip to content

Commit

Permalink
add "Rust's Almost-Rules and Almost-Almost-Rules"
Browse files Browse the repository at this point in the history
  • Loading branch information
soc committed Aug 6, 2024
1 parent 623c1cc commit 2529b3f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
41 changes: 41 additions & 0 deletions _languages/rust-almost-rules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: "Language Design: Rust's Almost-Rules and Almost-Almost-Rules"
date: 2024-08-05
---

(Inspired by [Almost Rules](https://matklad.github.io/2022/07/10/almost-rules.html).)

### Syntax edition

##### `:` is followed by a type

- except inside struct initializers, where it is followed by a value
- except function result types, that are preceded with `->`

##### generics use `<>`

- except in expression contexts, where `::<>` is used

##### invocations use `()`

- except where `{}` or `[]` is used, because "they convey important information"
- except for macro invocations, where `()`, `{}`, `[]` are equivalent and interchangeable

##### `T {}` initializes a struct

- except inside an `if`, where `{` starts a branch

##### Rust has no varargs

- except for `extern` functions
- except for macros

##### `let` introduces a binding

- except in pattern matching, where `let` is implied
- except if the match starts with an uppercase letter, then it refers to an identifier in the outer scope
- except in macro pattern matching, where it is matched verbatim

##### types with a total order implement `Eq` and `Ord`

- except `f64` and `f32`, which do not
3 changes: 2 additions & 1 deletion index.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ navigation: true
<li><a href="languages/popular-but-wrong">Popular, but Wrong</a></li>
<li><a href="languages/implicit-numeric-conversions" class="compact">Implicit Numeric Conversions</a></li>
<li><a href="languages/package-objects-in-scala">Package Objects in Scala</a></li>
<li><a href="languages/lower-bar-of-rust-2">The lower bar of "Rust 2.0"</a></li>
<li><a href="languages/rust-almost-rules">Rust's Almost-Rules</a></li>
<li><a href="languages/rust-struct-initializer-mistake">Struct initialization in Rust</a></li>
<li><a href="languages/lower-bar-of-rust-2">The lower bar of "Rust 2.0"</a></li>
<li><a href="languages/design-mistakes-in-rust">(More) Rust Design Mistakes</a></li>
</ul>
</section>
Expand Down

0 comments on commit 2529b3f

Please sign in to comment.