The starting state for our repo after the csv upload course is a Cargo Workspace, which means we can add a new package to the crates directory.
To add a new crate to the workspace we can use cargo new
on the directory that we want the crate to live in. In our case we'll put that in crates/pokemon-api
which results in a new crate called pokemon-api
in our workspace members directory.
cargo new crates/pokemon-api
You should see a typical new Rust project in crates/pokemon-api
, including a scaffolded Cargo.toml
.
[package]
name = "pokemon-api"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
Building crates
If we run cargo build
now.
cargo build
cargo will try to build the whole workspace. We know this because we'll get a build error for the upload-pokemon-api
saying it needs DATABASE_URL
set to build properly.
error: `DATABASE_URL` must be set, or `cargo sqlx prepare` must have been run and .sqlx must exist, to use query macros
To build a specific package (pokemon-api
) we can use the -p
flag.
cargo build -p pokemon-api
Since we also know the binary name, we could use the --bin
flag as well.
cargo build --bin pokemon-api
The difference between these two flags is that a package can contain multiple binaries, so -p
would build all of the binaries in that package while --bin
would only build one.
Cargo.lock
When we create the new crate, we also get a change to Cargo.lock
reflecting that.
+[[package]]
+name = "pokemon-api"
+version = "0.1.0"