Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

directory ancestors (parent directories)

use std::path::Path;

fn main() {
    let path = Path::new("one/two/three/four.rs");
    println!("{}", path.display());

    for p in path.ancestors() {
        println!("{}", p.display());
    }
}
one/two/three/four.rs
one/two/three/four.rs
one/two/three
one/two
one