Skip to content

Instantly share code, notes, and snippets.

@ahl
Created August 24, 2022 21:25
Show Gist options
  • Save ahl/cc69a6b267bc04ec48a7dca1b9630578 to your computer and use it in GitHub Desktop.
Save ahl/cc69a6b267bc04ec48a7dca1b9630578 to your computer and use it in GitHub Desktop.
rust for rustaceans (what I learned)
Rust for rustaceans
Ch 1
Uses of multiple lifetime bounds within a single function or type eg a string split iterator
Ch 2
Use trait associated types rather than trait genetics except if you expect multiple implementations of the trait for a given type
You can use impl trait as the value for an associated type and the compiler will infer the specific type from use eg the return from IntoIterator::into_iter()
fn foo(x: impl Whatever) is short for <T: whatever> … I haven’t seen this. Is it a convention that people prefer not to use??
Ch 3
Have Error types smaller than the Result::Ok so use a Box if necessary
Ch 6
“Not all compiler warnings are enabled by default. Those disabled by default are usu-
ally still being refined, or are more about style than content. A good example of this is
the "idiomatic Rust 2018 edition" lint, which you can enable with #!(warn(zust 2018
idioms)]. When this lint is enabled, the compiler will tell you if you're failing to take
advantage of changes brought by the Rust 2018 edition. Some other lints that you may
want to get into the habit of enabling when you start a new project are missing does
and missing_debug_implementations, which warn you if you've forgotten to document
any bublic items in your crate or add Debug implementations for any public types,
respectively.”
Ch 7
#[macro_export] on a macro hoists it to the root of the crate. Should we put this on usdt macros?
Crate phf for perfect hashing
Ch 8
RawWakerVTable to make a futures Waker
Ch 9
dropck_eyepatch
Ch 13
Cargo-outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment