clap
is a fantastic Rust library
for Command Line Argument Parsing. It's both
easy to use and powerful - in the spirit of Rust philosophy - you get what
you pay for. Simple CLI options are simple to define, while complex schemes
(think git
level of complex) are absolutely doable.
clap
is also one of the best examples of what I would call
developer marketing in the Rust community. It has a
beautiful and informative homepage, an extensive
README (including changelog - see note
below), a bunch of
good examples, even
video tutorials!
Hats off to Kevin and all clap
contributors, you're doing a great job!
Note: Rust crate authors, please, please add changelogs/release notes to
your libraries. Coming from Python where it's customary, it struck me that
a lot of libraries do not document their changes aside from the commit log.
(Oops, I'm guilty of this myself...)
Continue reading »
We learned the basic concepts of nom
yesterday
when we wrote a parser for HTTP headers. HTTP is by its nature a text protocol.
nom
however always works on bytes (byte array slices, denoted in Rust with
&[u8]
). This makes it perfectly suitable for parsing binary data as well.
There's already a selection of parsers using nom
for binary formats such as
Redis dump files,
MySQL protocol
or tar archives. Today we are going
to build a simplified WebSocket frame parser.
Continue reading »
Important note: this article is outdated! Go to http://zsiciarz.github.io/24daysofrust/ for a recent version of all of 24 days of Rust articles. The blogpost here is kept as it is for historical reasons.
One of the few chores when building a commandline program is argument parsing, so that myprogram --config=myfile.conf --verbose -o output.txt
makes sense. Some arguments come in short and long variants, some are optional and some are positional only. There are a lot of libraries for argument parsing, some are even included in the respective languages' distributions. In Rust's case there's the getopts crate.
The first thing a moderately savvy user will do is... no, not read the documentation, but run myprogram -h
(or --help
) to discover available options. getopts
and other libraries can derive such help summary for you, saving your time and reducing duplication. But what if it was the other way round? You'd write the usage message, listing possible options, and the tool would build an argument parser from that. Enter docopt.
Continue reading »
Important note: this article is outdated! Go to http://zsiciarz.github.io/24daysofrust/ for a recent version of all of 24 days of Rust articles. The blogpost here is kept as it is for historical reasons.
Most of us programmers have encountered the CSV format at some point of our career. Whether you cooperate with financial people, analyze some scientific data or simply allow the users of your web app to download a record of their activities, chances are you'll use some variation of CSV as the data format. Note that I said some variation - CSV itself isn't standardized and there are lots of quirks in different implementations.
CSV libraries exist for lots of languages, making it a common format for interoperability (alongside XML or JSON) and sometimes preferred for data of a tabular nature. In the Rust ecosystem there is the csv crate which will be the focus of this blog post.
Continue reading »