We can understand recursive search by following a few steps:
- Open a Terminal to create a new project using cargo new filesystem. Use VS Code to open the project directory.
- Edit Cargo.toml to add a dependency to a crate called glob for walking the filesystem:
[dependencies]glob = "0.3.0"
- In src/main.rs, we can then start implementing functions to walk the filesystem tree, but first, let's set up the imports and a type alias for boxed errors:
use glob;use std::error::Error;use std::io;use std::path::{Path, PathBuf};type GenericError = Box<dyn Error + Send + Sync + 'static>;
- Next, we are going to add a recursive walk function that is only using the Rust standard library. Add the following:
fn walk(dir: &Path, cb: &dyn ...