diff --git a/_languages/rust-almost-rules.md b/_languages/rust-almost-rules.md new file mode 100644 index 0000000..301c0fb --- /dev/null +++ b/_languages/rust-almost-rules.md @@ -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 the identifiers in the outer scope + - except in macro pattern matching, where it matches it as an identifier verbatim + +##### types with a total order implement `Eq` and `Ord` + +- except `f64` and `f32`, which do not diff --git a/index.md b/index.md index 44ae46d..d73d961 100644 --- a/index.md +++ b/index.md @@ -72,8 +72,9 @@ navigation: true
  • Popular, but Wrong
  • Implicit Numeric Conversions
  • Package Objects in Scala
  • -
  • The lower bar of "Rust 2.0"
  • +
  • Rust's Almost-Rules
  • Struct initialization in Rust
  • +
  • The lower bar of "Rust 2.0"
  • (More) Rust Design Mistakes