Libraries

There are many excellent Rust libraries (and also many poor ones of course). These are all collected at crates.io, the Rust language-specific package repository.

For most programs, use of ecosystem library packages is a practical necessity.

Rust's excellent metaprogramming system makes it possible for libraries to provide facilities that resemble bespoke language features.

When searching for libraries, usually use the opinionated catalogue at lib.rs. Or use "recent downloads" for the search order on crates.io, which is inexact but is likely to give you fate-sharing with the rest of the community, at least.

Libraries you should know about

Libraries for specific purposes

serde

serde is a serialisation/deserialisation framework.

It defines a data model, and provides automatic translation of ordinary Rust structs to and from that model.

Ecosystem libraries provide concrete implementations for a wide variety of data formats, and some interesting data format metaprogramming tools.

The result is a superb capability to handle a wide variety of data marshalling problems. serde is especially good for ad-hoc data structures and structures whose definition is owned by a Rust project.

serde and its ecosystem are considerably better for many tasks than anything available in any other programming environment.

Generally, the resulting code is a fully monomorphised open-coded marshaller specialised for the specific data structure(s) and format(s), so performance is good but the code size can be very large.

Web tools and frameworks

Most Rust web tools are async.

Use reqwest or ureq for making HTTP requests.

Use hyper for a raw HTTP client or server, but consider using reqwest (client) or a web framework (server) instead.

Rust is well supplied with web frameworks, but it is hard to choose.

  • I have been using Rocket for some years, But development is rather slow - there still isn't a final release of rocket 0.5. You should use the 0.5 preview.

  • axum is from the Tokio team, but quite new.

  • actix-web is very popular, but sometimes lacking attention to detail.

  • rouille is sync. Yay! But I haven't tried it.

  • You should perhaps also consider: warp.

Command line parsing: clap

If you are writing a command line program you should probably use clap. It allows declarative definition of command line options.

Unfortunately, clap has some problems.

  • Serious problems handling options which override each other. There is a facility for this but it is not convenient and its algorithm is fundamentally wrong.

  • General failure to follow (at least by default) well-established Unix option parsing conventions.

To illustrate: it is quite awkward even to provide a conventional pair of mutually-overriding --foo and --no-foo options.

In practice, using clap means accepting that one's program will have an imperfect and sometimes-balky command line syntax.

There are alternatives, notably getopts, gumdrop and argparse, but they are much less popular and less well maintained. I sometimes use argparse where I want a fine-tuned option parser, but it is quite odd and the docs are not great.