- Open the Cargo.toml file in your favorite text editor; in this recipe, we will use the nano editor:
nano Cargo.toml
You should get the following output:
- Add a [dependencies] section to the cargo.toml file and enter time = "0.1.12" and regex = "0.1.41" below it.
You should get the following output:
- Use the cat command to see the configuration list:
cat Cargo.toml
You should get the following output:
- Build the project to pull the dependencies from https://crates.io/:
cargo build
You should get the following output:
- Use the existing crates pulled in our project.
Open the main.rs file in the src directory using nano and enter the following code:
nano main.rs
You should get the following output:
// Declare the external crate
extern crate regex;
use regex::Regex;
fn main() {
let check_date = Regex::new(r"^d{4}-d{2}-d{2}$").unwrap();
println!("Did our date match? {}", check_date.is_match("2017
-02-01"));
}
You should get the following state output:
- Compile and run the project:
cargo run
You should get the following output: