std-method

Path::parent: immediate lexical parent

Obtain the lexical parent without resolving links or consulting the disk. A one-component relative name can have an empty parent. Expected stdout (not executed): true Common mistake: Assuming the parent exists on disk.

Formal Syntax & Structure

rust syntaxrust
path.parent() -> Option<&Path>

Working Example

Example Snippetrust
fn main() {    use std::path::Path;    let p = Path::new("reports/today.csv");    println!("{}", p.parent() == Some(Path::new("reports")));}
Rust Reference