Skip to content

Latest commit

 

History

History
174 lines (105 loc) · 7.38 KB

File metadata and controls

174 lines (105 loc) · 7.38 KB

Rust

Getting started

Use rustup to install the toolchain.

Installing the Rust compiler and toolchain

Learn Rust

Google's Rust training

Books

IDE setup

Rust on Nails uses development containers in VS Code for a rust app. Very helpful.

Async related

async/await Pin related Futures

Error related

A great walkthrough of error handling by the Zero to Production in Rust author.

Recoverable Errors with Result

API related

Optimizations

Paraphrasing: But if you need to squeeze every bit of speed out of it, add lto = true to your release profile in your cargo.toml to enable link time optimizations. It increases build times for your release builds, but I find it gives 10-20% better performance.

More: cargo run will also build, so if you do cargo build --release followed by cargo run then it will run an unoptimized build

Lifetimes

Outlines the various meanings of 'lifetime' wording.

Closures

A great writeup detailing differences of Fn, FnOnce, and FnMut.

Tracing

This covers the hows and whys of moving from logging to tracing.

Ownership

OP asked about mutability, but the core issue involves ownership.

We can use as &_ and others.

//option 1
let x = &mut whatever;
let y = &*x;
//option 2
let y: &_ = x;
//option 3
let x = &*x;

Standard library goodness

Concat various types

Destructuring

Function arguments can be destructured as shown in this thread.

In Rust, anytime you have a binding -- ie, you define a name for a variable -- you have pattern-matching:

let Args { opt_a, opt_b } = args;

fn foo(Args { opt_a, opt_b }: Args);

For let, you can even use refutable patterns, by using let..else:

let Some(a) = a /_Option<A>_/ else {
    return x;
};

More examples

struct Args { opt_a: i32, opt_b: u32, }

//fn my_function(args: Args) {}
fn my_function(Args {opt_a, opt_b}: Args) {
    println!("{} {}", opt_a, opt_b);
}

fn main() {
    my_function(Args { opt_a: 1, opt_b: 4, });
}

and Defaults can be added by implementing Default on the Args struct and using ..Default::default() at the callsite.

foo

From and Into round-up

TODO: pull the important bits from the following

https://old.reddit.com/r/rust/comments/14uxt10/from_vs_into_which_should_generic_free_functions/

https://www.reddit.com/r/rust/comments/anezli/when_to_use_from_vs_into/?utm_source=reddit&utm_medium=usertext&utm_name=rust&utm_content=t1_jr9rr8b

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=7b0c0bc8e0fc65d30b313899a0d7480c

https://ricardomartins.cc/2016/08/03/convenient_and_idiomatic_conversions_in_rust

Unsorted

The Little Book of Rust Books

https://github.com/sger/RustBooks

You can implement a trait for Reference which they say can also be done for Mutable Reference.

godbolt can be used to decompile a rust program.

criterion for benchmarks cargo-flamegraph for performance profiling dhat for heap profiling

For any crates you like at crates.io, add them to your following list.

Check for gems here

Using various lists

Link to std lib. Link to crate docs.

Blessed - An unofficial guide to the Rust ecosystem

Check out the github star list.

A tour of standard library traits.

Rustlings are small exercises.

From Learn Rust the Dangerous Way

  • Document the compiler version you tested with, or ideally, pin it in your build system. (Rust has the rust-toolchain file to do this.)
  • Include a benchmark test that will indicate if things have suddenly gotten slower, so you can at least know to investigate. Ensure that this test runs as part of the build or continuous integration flow. (For Rust projects using Cargo, I recommend Criterion.)

Rust Language Cheat Sheet

A great deep dive into unique access.

Enabling debug info