std-method

PathBuf::push and pop: mutate a path

Append a relative component and remove the last component in place. Absolute or rooted operands have platform-specific replacement rules. Expected stdout (not executed): true true Common mistake: Using pop to delete a file.

Formal Syntax & Structure

rust syntaxrust
path.push(part); path.pop() -> bool

Working Example

Example Snippetrust
fn main() {    use std::path::{Path, PathBuf};    let mut p = PathBuf::from("reports");    p.push("daily.txt");    println!("{}", p.pop());    println!("{}", p == Path::new("reports"));}
Rust Reference