Path and Filesystem Models
Join Path Segments
Build a Child Path
Path::join appends a child path to a base path and returns an owned PathBuf.
Program
Play the program to choose a child path and join it under a fixed target directory.
join_path_segments.rs
use std::path::Path;
fn main() {
let file = ;
let base = Path::new("target");
let full = base.join(file);
println!("{}", full.display());
}
use std::path::Path;
fn main() {
let file = ;
let base = Path::new("target");
let full = base.join(file);
println!("{}", full.display());
}
use std::path::Path;
fn main() {
let file = ;
let base = Path::new("target");
let full = base.join(file);
println!("{}", full.display());
}
join
`join` creates a child path without changing the base path.
PathBuf
The joined result is owned so it can be moved or changed later.
display
`display` formats a path for user-facing output.