macro_rules! path {
() => { ... };
($single:literal) => { ... };
($first:expr $(, $rest:expr)* $(,)?) => { ... };
}Expand description
Constructs a path with compile-time optimization for literals.
This macro provides ergonomic path construction with optimal performance:
- Single string literal returns
&'static Path(zero allocation!) - Multiple arguments or runtime values return
PathBuf
§Syntax
path!()- Empty path (PathBuf)path!("user.profile.name")- Single literal (&’static Path, zero-cost!)path!("user", "profile", "name")- Multiple components (PathBuf)path!(base, "profile", "name")- Mix runtime and literals (PathBuf)path!(existing_path)- Pass through existing paths (PathBuf)
§Examples
// Zero-cost literal (returns &'static Path)
let path = path!("user.profile.name");
// Multiple components (returns PathBuf)
let path = path!("user", "profile", "name");
// Mixed runtime/literal (returns PathBuf)
let base = "user";
let path = path!(base, "profile", "name");
// Empty path
let empty = path!();