How to Work with File Paths in Rust (PathBuf, Path)

Use PathBuf for mutable paths and Path for immutable references in Rust file system operations.

Use PathBuf for mutable file paths and Path for immutable references; convert between them using .as_path() or Path::new().

use std::path::{Path, PathBuf};

fn main() {
    let mut path = PathBuf::from("/home/user/docs");
    path.push("file.txt");
    let path_ref: &Path = path.as_path();
    println!("Path: {:?}", path_ref);
}