How to do it...

Follow these steps:

  1. Open the Cargo.toml file that was generated earlier for you.

  2. Under [dependencies], add the following line:
glob = "0.2.11"
  1. If you want, you can go to glob's crates.io page (https://crates.io/crates/glob) to check for the newest version and use that one instead.
  2. In the bin folder, create a file called glob.rs.

  3. Add the following code and run it with cargo run --bin glob:

1    extern crate glob;
2 use glob::{glob, glob_with, MatchOptions};
3
4 fn main() {
5 println!("All all Rust files in all subdirectories:");
6 for entry in glob("**/*.rs").expect("Failed to read glob
pattern") {
7 match entry {
8 Ok(path) => println!("{:?}", path.display()),
9 Err(e) => println!("Failed to read file: {:?}", e),
10 }
11 }
12
13 // Set the glob to be case insensitive and ignore hidden
files
14 let options = MatchOptions {
15 case_sensitive: false,
16 require_literal_leading_dot: true,
17 ..Default::default()
18 };
19
20
21 println!(
22 "All files that contain the word "ferris" case
insensitive
23 and don't contain an underscore:"
24 );
25 for entry in glob_with("*Ferris[!_]*",
&options).expect("Failed to read glob pattern") {
26 if let Ok(path) = entry {
27 println!("{:?}", path.display())
28 }
29 }
30 }
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.249.210