Managing our code with crates and Cargo instead of pip
Building our own application is going to involve the following steps:
- Create a simple Rust file and run it.
- Create a simple application using Cargo.
- Run our application using Cargo.
- Manage dependencies with Cargo.
- Use a third-party crate to serialize JSON.
- Document our application with Cargo.
Before we start structuring our program with Cargo, we should compile a basic Rust script and run it:
- To do this, make a file called
hello_world.rs
with the main function housing theprintln!
function with a string, as we can see here:fn main() { println!("hello world"); }
- Once this is done, we can navigate to the file and run the
rustc
command:rustc hello_world.rs
- This command compiles the file into a binary to be run. If we compile on Windows, we can run the binary with the following command:
.\hello_world.exe
- If we compile it on Linux or Mac, we can...