`as`: `x as T` can do lossy conversion, so prefer `T::try_from(x).expect("…")` if you want it to fail loudly (e.g., if a u64 doesn't fit in a u32). 2/39 rust-lang.github.io/rust-clippy/ma…
`async`: in `async` blocks, `return` and `?` only bubble to the result of the future, whereas `break` and `continue` would affect the outer context and so re disallowed. 3/39 doc.rust-lang.org/stable/referen…
`await`: `await` is nothing but syntactic sugar for a `loop` that calls `Future::poll` and calls `yield` on `Poll::Pending`. 4/39 github.com/rust-lang/rust…
`break`: You can pass a value to break in a `loop` to make the `loop` evaluate to that value. 5/39 doc.rust-lang.org/stable/referen…
`const`: There are a _lot_ more constifications planned, including allowing `async {}` in `const fn`! 6/39 github.com/rust-lang/rust…
`crate`: These days, the two primary uses of `crate` as a standalone keyword have mostly gone away: `extern crate` is rarely used, and `crate` as a visibility modifer won't happen (just use `pub(crate)` instead). 8/39 github.com/rust-lang/rust…
`dyn`: `dyn` trait objects come with a default lifetime bound inherited from the containing wide pointer type. 9/39 doc.rust-lang.org/stable/referen…
`else`: `else` is about to get another meaning with let-else expressions, which are like `.unwrap_or` for pattern matches! 10/39 github.com/rust-lang/rust…
`enum`: For data-less enums ("C-style enums"), you can assign a value to only a _subset_ of the variants, and the remaining ones get inferred automatically. 11/39 doc.rust-lang.org/stable/referen…
`fn`: You can write `#![attr]` immediately _inside_ a function to add attributes to the function itself (though it's not very idiomatic). 14/39 doc.rust-lang.org/stable/referen…
`for`: `for` loops are really just syntax sugar for a `loop` that calls `IntoIterator::into_iter` and then matches on `Iterator::next`. 15/39 github.com/rust-lang/rust…
`if`: 🤔🤷 16/39
`impl`: You can put `const`s directly in `impl` blocks to make "associated constants" for a type. 17/39 doc.rust-lang.org/stable/referen…
`in`: Not specifically about `in`, but any `..` expression is actually just a convenient constructor for a `Range` type. 18/39 doc.rust-lang.org/stable/referen…
`let`: The interaction between `let _ ` and dropping are subtle and interesting. 19/39 github.com/rust-lang/rust…
`loop`: There used to be a mode in the Rust compiler that turned every function body into `loop {}`, which was used (among other things) to make `rustdoc` faster. It was called "everybody loops" 😆. 20/39 github.com/rust-lang/rust…
`mod`: You can make `mod` load files from non-standard locations using the `#[path]` attribute. Though use it sparingly, as it can be very confusing for other developers trying to sort through your code base. 22/39 doc.rust-lang.org/stable/referen…
`move`: The "opposite" capture behavior of `move` (that is, if `move` _isn't_ passed), is far from straightforward. 23/39 doc.rust-lang.org/stable/referen…
`mut`: While `mut` is *techically* short for "mutable", you're generally better off thinking about it as "MUTually exclusive". 24/39 docs.rs/dtolnay/latest…
`pub`: There are a lot of visibility modifiers between non-`pub` and `pub`. `pub(crate)` and `pub(super)` are both useful, but you can even specify `pub(in crate::some_mod)` to get really specific. 25/39 doc.rust-lang.org/stable/referen…
`ref`: You can use `ref` to match something as a reference in a pattern, instead of capturing it as a value. That's not a secret of `ref`, it's just what it means, but it's so commonly confused that it's worth repeating. 26/39 doc.rust-lang.org/stable/referen…
`return`: `return` has a secret, long-unimplemented sibling, `become`, which is intended to one day maybe be used for functions that require guaranteed tail-call optimization. 27/39 rust-lang.github.io/rfcs/0601-repl…
`self`: `self` is special when it comes to automatic inference of the lifetime of return values. Specifically, the lifetime of a `&self` or `&mut self` argument will always be inferred to be the lifetime of the return value (if lifetimes are elided). 28/39 doc.rust-lang.org/stable/referen…
`static`: You can declare `static` items inside function bodies to get a `static` that only that function has access to (unless it gives out references). This can be handy for implementing singleton-like patterns. 30/39 doc.rust-lang.org/stable/referen…
`struct`: A tuple-like struct implicitly defines a free-standing function by the same name that acts as the type's constructor. And a unit-like struct implicitly defines a constant by that name! 31/39 doc.rust-lang.org/stable/referen…
`super`: `super` is only permitted to follow either another `super` or an initial `self` in paths, and if it follows a `self` then the `self` is effectively ignored. 32/39 doc.rust-lang.org/stable/referen…
`true`: Even though bools in Rust are generally `u8`s internally, it is illegal for `true` to be represented by anything but `0x01`. This is to enable optimizations that use other bitpatterns to compress state (like Option<bool>::None == 0x02). 34/39 github.com/rust-lang/rfcs…
`unsafe`: You don't currently have to use `unsafe {}` to perform unsafe operations inside an `unsafe fn`, though that's likely to get a lint in the future to encourage fine-grained safety tracking (and thinking). 36/39 github.com/rust-lang/rust…
`use`: You can use the syntax `use path::to::Trait as _` to bring a trait into scope (so you can call its methods) without also bringing the name into scope. Handy in cases where two traits have the same name for example. 37/39 doc.rust-lang.org/stable/referen…
`where`: `where` clauses do not _need_ to reference the generic type parameters of the thing they're attached to. You can write, for example: `where String: Clone` if you want to. 38/39 doc.rust-lang.org/stable/referen…
`while`: While loops are particularly handy for cases where the iterator type is useful beyond iteration. For example, if you're iterating over a `Path` (with `Path::iter`), you can call `.as_path()` on the iterator to get the _remaining_ `Path`. 39/39 doc.rust-lang.org/std/path/struc…
• • •
Missing some Tweet in this thread? You can try to
force a refresh
Okay, learning time! Name a @rustlang type (can be generic), and I'll (try to) tell you something you didn't know about that type!
I'm guessing this will be a learning experience as much for me too, as I'm sure there are some I'll have to dig a bit to get at something new and interesting for 😅
I had a conversation about how to get signals about the health of and love for open-source projects recently, and had this (potentially erroneous) thought: bug reports are positive signals, while feature requests are negative.
A bug report means that a) someone is using your project, b) they care enough to file an issue, and c) they didn't just immediately switch to another project instead.
A feature request _also_ means that someone is using your project and care enough to file, but is additionally an indicator that their needs aren't currently (completely) served by the project. That's not the be-all and end-all, but it _is_ an indication of pain.
Big announcement time 📢 For a while now, I've been working on a book that covers the next steps of @rustlang after "the book" — everything from API design to error handling to concurrency to async to FFI. And the early access was just released over at nostarch.com/rust-rustaceans! 🎉
The book is, as its name implies, written for people who are already familiar with Rust. The idea is that you read The Rust Programming Language first, play around with Rust for a bit on your own, maybe start using it "for real", and then pick this up to hone your skills.
It's written so that each chapter is more or less standalone, so you can read up on the subjects you want to know more about, rather than having to read through the whole thing start-to-finish. Though of course you can do that too if you want!