std-method

Path::join: build a child path

Create a new combined path without modifying the original. An absolute argument can replace the base; joining untrusted input is not a containment check. Expected stdout (not executed): true true Common mistake: Assuming join always keeps an input below the base.

Formal Syntax & Structure

rust syntaxrust
path.join(other) -> PathBuf

Working Example

Example Snippetrust
fn main() {    use std::path::Path;    let base = Path::new("logs");    let joined = base.join("app.txt");    println!("{} {}", joined.starts_with(base), base == Path::new("logs"));}
Rust Reference