This Week I Learned: 2022W42

Mon Oct 24 2022

Rust - Order of execution

It seems like in Rust, the order of execution is sometimes unusual.

Consider this piece of code:

let guess: u32 = "42".parse().expect("Not a number!");

Let’s omit the expect method (which is really interesting) here.

If we don’t use the type annotation (u32), there is a compiler error because Rust doesn’t know how to parse the string:

// Won't compile
let guess = "42".parse().expect("Not a number!");

In other languages you might expect something like a parameter of the parse function to indicate the target type:

let guess = "42".parse(u32).expect("Not a number!");

Here, the type annotation which is on the left side of the evaluation, changes what happens on the right part of the line. It’s very unusual and confusing to me.

fzf - Git

fzf has a multi select line when adding the -m option. Then you can use Tab to select multiple entries.

If you add this into your .gitconfig file, you can then use git fd to delete multiple branches at once by selecting them. So lovely.

    # Delete branches from your recent used ones
    fd = "!f() { git branch -a --sort=-committerdate | grep -v remotes\\/ | fzf -m | sed 's/remotes\\/origin\\///' | xargs -o git br -D; }; f"

You can see it in action here.