Get the latest tech news

Parsing arguments in Rust with no dependencies


Monday, November 4, 2024 When pairing with my friend Emily, we had a choice of what to implement in her project: start a new feature, or add a command line argument parser? We opted for the latter, because it had to happen eventually and it was more well bounded. It ended up having a lot of depth! We wrote it from scratch to learn more, rather than pulling in a library1.

When pairing with my friend Emily, we had a choice of what to implement in her project: start a new feature, or add a command line argument parser? I think this is a reasonable tradeoff, since it keeps the code simple and it remains flexible, but the cost is that this means checking if an incorrect value is passed in (say, "fiddlesticks" for something that expects an integer) is pushed off as the user's responsibility, making the library harder to use. Then you could add in a lot of "fit for purpose" simple 0-dep things, and pick up the complex ones for where you really need it while still keeping your Cargo.lock slimmer than today.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Rust

Rust

Photo of arguments

arguments

Photo of Dependencies

Dependencies

Related news:

News photo

Why I love Rust for tokenising and parsing

News photo

Bringing Faster Exceptions to Rust

News photo

Show HN: Whirlwind – Async concurrent hashmap for Rust