Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Rust notes

Learning

TODO:

Great rewrites

Fish Nushell Ripgrep Fd Bat Eza Zoxide Xh Zellij Gitui du-dust dua starship yazi hyperfine evil-helix bacon cargo-info fselect ncspot rusty-man delta ripgrep-all tokei wiki-tui just mask mprocs presenterm kondo bob-nvim https://github.com/jdx/mise espanso

Wrapper types

Box This abstraction is a low cost abstraction for dynamic allocation. If you want to allocate some memory on the heap and safely pass a pointer to that memory around, this is ideal.

Rc is a reference counted pointer for multiple owning.

Source: Wrapper types

Articles

  • Some nice tipps & tricks from federicoterzi
  • Great google book for learning rust in 3 days (android) google

Error handling

Rusts result type is a great construct for creating error chains, something like:

#![allow(unused)]
fn main() {
fn read_config_file(path: &str)
    -> Result<String, ConfigFileError> {
    std::fs::read_to_string(path)
        .map_err(ConfigFileError::ReadError)
}

fn parse_config_file(file: String) 
    -> Result<i32, ConfigFileError> {
    file.parse()
        .map_err(ConfigFileError::ParseError)
}

fn work_with_config_file(path: &str) 
    -> Result<i32, ConfigFileError> {
    // No ? required at all - just directly return
    // the Result, since the types match!
    read_config_file(path).and_then(parse_config_file)
    // .and_then(something_else).and_then(even_more_things) ....
}
}

Source: naiveai, bruntsushi

Last change: 2025-05-28, commit: 18a1b16