Course lesson
Initialize a new Cargo binary crate in a new package
By default cargo initializes a new package containing a binary crate. The file that gets compiled into the binary is located at src/main.rs. This is by convention and we can specify different paths and names for binaries.
- Duration
- 2 min
- Access
- Pro
- Transcript
- Available
cargo initBy default cargo initializes a new package containing a binary crate.
The file that gets compiled into the binary is located at
src/main.rs. This is by convention and we can specify different paths
and names for binaries.
We also get a Cargo.lock and a Cargo.toml. These are similar to
JavaScript's package.json and package-lock.json or yarn.lock.
The Cargo.toml defines different features of our package including
dependencies, defining zero or one library crates, and defining as
many binary crates as we want.
We can run the new binary with cargo run.
❯ cargo run
Compiling digital-garden-steps v0.1.0 (/digital-garden-steps)
Finished dev [unoptimized + debuginfo] target(s) in 1.38s
Running `target/debug/digital-garden-steps`
Hello, world!