- Create a Rust project to work on during this chapter with cargo new chapter_five.
- Navigate into the newly created chapter_five folder. For the rest of this chapter, we will assume that your command line is currently in this directory.
- Inside the src folder, create a new folder called bin.
- Delete the generated lib.rs file, as we are not creating a library.
-
Open the Cargo.toml file that was generated earlier for you.
- Under [dependencies], add the following lines:
lazy_static = "1.0"
regex = "0.2"
If you want, you can go to the crates.io web pages for lazy_static (https://crates.io/crates/lazy_static) and regex (https://crates.io/crates/regex) to check for the newest version and use that one instead.
- In the src/bin folder, create a file called lazy_static.rs
- Add the following code and run it with cargo run --bin lazy_static:
1 #[macro_use]
2 extern crate lazy_static;
3 extern crate regex;
4
5 use regex::Regex;
6 use...