Let's create a new project with all the necessary dependencies. We will create a binary utility for managing users in a database. Create a new binary crate:
cargo new --bin users
Next, add the dependencies:
cargo add clap postgres
But wait! Cargo doesn't contain an add command. I've installed cargo-edit tool for managing dependencies. You can do this with the following command:
cargo install cargo-edit
The preceding command installs the cargo-edit tool. If you don't install it, your local cargo won't have an add command. Install the cargo-edit tool and add the postgres dependency. You can also add dependencies manually by editing the Cargo.toml file, but as we are going to create more complex projects, the cargo-edit tool can be used to save us time.
Also, add the clap crate. We need it for parsing arguments for our tool. Add the usages of all the necessary types, as follows:
extern crate clap;
extern crate postgres;
use clap::{
crate_authors, crate_description, crate_name, crate_version,
App, AppSettings, Arg, SubCommand,
};
use postgres::{Connection, Error, TlsMode};
All necessary dependencies have been installed, and our types have been imported, so we can create the first connection to a database.