### Compute Relative Paths with diff_paths Source: https://context7.com/manishearth/pathdiff/llms.txt Demonstrates how to use the diff_paths function to calculate the relative path between two standard filesystem paths. It accepts types implementing AsRef and returns an Option. ```rust use pathdiff::diff_paths; use std::path::{Path, PathBuf}; fn main() { let result = diff_paths("/home/user/projects/app", "/home/user/documents"); assert_eq!(result, Some(PathBuf::from("../projects/app"))); let result = diff_paths("/foo/bar", "/foo/bar/baz/quux"); assert_eq!(result, Some(PathBuf::from("../../"))); let result = diff_paths("/foo/bar/baz", "/foo/bar"); assert_eq!(result, Some(PathBuf::from("baz"))); let target = Path::new("/workspace/src/main.rs"); let base = PathBuf::from("/workspace/tests"); let result = diff_paths(target, base); assert_eq!(result, Some(PathBuf::from("../src/main.rs"))); } ``` -------------------------------- ### Compute Relative UTF-8 Paths with diff_utf8_paths Source: https://context7.com/manishearth/pathdiff/llms.txt Shows how to use diff_utf8_paths to compute relative paths using UTF-8 aware types from the camino crate. This requires the 'camino' feature to be enabled in the project dependencies. ```rust use pathdiff::diff_utf8_paths; use camino::{Utf8Path, Utf8PathBuf}; fn main() { let result = diff_utf8_paths("/home/user/docs", "/home/user/projects"); assert_eq!(result, Some(Utf8PathBuf::from("../docs"))); let target = Utf8Path::new("/workspace/src/main.rs"); let base = Utf8Path::new("/workspace/tests").to_path_buf(); let result = diff_utf8_paths(target, base); assert_eq!(result, Some(Utf8PathBuf::from("../src/main.rs"))); let result = diff_utf8_paths("../foo/bar/baz", "../foo"); assert_eq!(result, Some(Utf8PathBuf::from("bar/baz"))); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.