macro_rules! join_paths {
($base:expr, $($sub_path:expr),+) => { ... };
}
Expand description
Combines multiple paths into a single valid path, handling overlapping slashes.
- Removes trailing slashes from the base path.
- Removes leading slashes from subsequent paths to avoid duplication.
- Supports multiple path segments for flexible usage.
§Parameters
base
: The base path as a string slice. It serves as the starting point for the combined path.sub_path
: One or more subsequent paths as string slices. These are appended to the base path in order.
§Returns
String
: The resulting combined path as aString
, with platform-specific separators and cleaned of redundant slashes.
§Example
use std_macro_extensions::*;
let combined_path: String = join_paths!("/home/", "/user/", "/documents", "file.txt");
assert_eq!(combined_path, "/home/user/documents/file.txt");
let another_path: String = join_paths!("C:/", "/Program Files", "App");
assert_eq!(another_path, "C:/Program Files/App");