I've been programming in Rust for a few years now. I quite like the language, its tooling, and its library ecosystem. There's a few libraries ("crates") I especially like and use often. A short thread.

See https://blessed.rs/ for a list of "recommended crates" for a less personal list.

#Rust #RustLang

Crate List - Blessed.rs

clap is the command line argument parsing library. I especially like it because it lets me declare a struct, with strong Rust typing, to define what the command line should work like. I also like that meshes well with the tradition of Unix command line interfaces.

I've implemented command line parsing in C, shell, Python, and more. For a while the Python standard library had my implementation of getopt_long. clap is the only library for this that I actually enjoy using.

#Rust #RustLang

serde and the small ecosystem around it make it painless to serialize and deserialize structured data. I define a Rust type, annotate it with serde, and use serde-foo library to read and write files in format foo. I mostly use serde-json (for JSON) and serde-norway (for YAML) as those are the formats I mostly need.

#Rust #RustLang

thiserror lets me define error types. Rust has a powerful system for handling errors, which lets me write error messages that are useful to those using my software. This benefits from making many error types, from the very specific to the broad and general.

I'm tired of Unix programs saying "No such file or directory" without saying which file or directory doesn't exist. I want the programs I write to always be more helpful than that.

#Rust #RustLang

tempfile handles temporary files well. I need this surprisingly often, and tempfile has never left me wanting. It just works. No notes.

#Rust #RustLang

walkdir lets me scan directories for files. For some reason this is also something I often need to do. I spent a couple of years thinking I should write my own, to be a little more flexible and much faster. Then I benchmarked walkdir and it's damn fast. I haven't found a faster way to do what it does, yet.

#Rust #RustLang

(end)

@liw I just use “ignore”, which uses walkdir, but has support for gitignore style globbing, which I tend to eventually need anyway. When also using the parallel walker, it’s easy to build tools that finds the correct set of files from big hierarchy and process them very efficiently on all cores, it’s such a delight.

@liw
Reminds me of an old type of nerd joke.

% man why did you hit your wife
man: too many arguments

@liw no way. no way the serde library for yaml is called norway.

for context, the "norway problem":
country_codes:

  • GB
  • FR
  • CH
  • NO

when loaded becomes ['GB', 'FR', 'CH', false]

@liw Do you have an example of clap usage that you particularly like? (Otherwise, I'll just search for some random examples.)

@amenonsen I don't have anything I can easily point at, sorry. But maybe this blog post will do?

https://blog.liw.fi/posts/2023/clap/

Using clap to build nice command line interfaces

@liw It does help me get a general sense of it. Not wildly different from Python's argparse, but with a more compact notation, it seems. Thank you.
@liw @amenonsen Seems much like Python's click, or the "modern" Typer, which builds on it.
@jens @liw Thanks, I hadn't looked at either of those.
@liw yeah that area gets reinvented a lot. tricky for it to be a net win on complexity but when it does it rocks