liveBook · Manning

Cargo.toml

As explained in Rust Servers, Services, and Apps

Cargo.toml is a manifest file that declares a Rust package's metadata, dependencies, targets, and related Cargo configuration.

Cargo.toml is the manifest at a Rust project’s root. It records package configuration such as dependencies, workspace membership, and binary targets, connecting project structure to Cargo commands. section 4.1 section 3.1.1

Use Cargo.toml to configure:

  • A workspace and its member projects, such as tutor-nodb and tutor-db. section 4.1 section 3.1.1
  • Runtime, web, database, serialization, and utility dependencies with versions and feature flags. section 4.2.2 section 8.1
  • Named binary targets, including basic-server for an executable under src/bin. section 3.1.1

Database-backed service manifest

A tutor-db Cargo.toml can combine Actix Web, dotenv, sqlx with PostgreSQL and Tokio features, Serde, Chrono, and vendored OpenSSL. Cargo then runs the configured project with commands such as cargo run --bin iter1 -p tutordb. section 4.2.2

[dependencies]
#Actix web framework and run-time                                  #1
actix-web = "4.1.0"
actix-rt = "2.7.0"
#Environment variable access libraries
dotenv = "0.15.0"                                                  #2
 
#Postgres access library
sqlx = {version = "0.6.2", default_features = false, features =
["postgres","runtime-tokio-native-tls", "macros","chrono"]}      #3
 
# Data serialization library
serde = { version = "1.0.144", features = ["derive"] }             #4
 
# Other utils
chrono = {version = "0.4.22", features = ["serde"]}                #5
 
# Openssl for build (if openssl is not already installed on the dev server)
openssl = { version = "0.10.41", features = ["vendored"] }         #6

Inspect a complete dependency section showing versions, comments, default-feature control, and sqlx feature selection. section 4.2.2

How Rust Servers, Services, and Apps covers it

How deep it goes
Defines workspace membership, dependencies, feature flags, and binaries through concrete listings, but does not detail manifest syntax broadly.
Examples
Uses tutor-nodb and tutor-db workspaces, basic-server binaries, and manifests for Actix Web registration and sqlx database programs.
What it assumes
Assumes familiarity with Rust projects and shell commands while establishing workspace, package, dependency, and binary configuration in context.
What you can do after
Operate/configure Cargo projects by adding dependencies, selecting features, declaring binaries, and running workspace packages.
How it connects
Connects Cargo workspaces and binaries with Actix Web, sqlx, PostgreSQL, Serde, dotenv, and environment-based configuration.

Also explained in

Compare how 4 books explain cargo.toml →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust Servers, Services, and Apps. The section links point to the parts of the book it draws on.