On this page
  1. PathBuf
  2. Signature & Overview
  3. Notes & Pitfalls
  4. Example

PathBuf

Prev: `BufReader` | Up: io_and_fs | Next: `Read`
Rel: io_and_fs, rust/builtins
Ref: Rust std — PathBuf
Tags: #public #prog #rust #stdlib #io_and_fs #tier/core


Signature & Overview

PathBuf (owned)  |  &Path (borrowed)

Cross-platform filesystem path pair (analogous to String / &str).

Notes & Pitfalls

Example

use std::path::PathBuf;

fn main() {
    let mut p = PathBuf::from("src");
    p.push("main.rs");
    assert_eq!(p.file_name().and_then(|s| s.to_str()), Some("main.rs"));
    assert_eq!(p.extension().and_then(|s| s.to_str()), Some("rs"));
}

Linked from

Related notes