std-type
Metadata: inspect file attributes
Inspect file size and type. Metadata is a snapshot and may become stale. The path-based metadata call follows symbolic links. Run only inside a disposable working directory. The fixture must not already exist. Expected stdout (not executed): true 3 Common mistake: Using earlier metadata as proof that a later operation is safe.
Formal Syntax & Structure
rust syntaxrust
fs::metadata(path) -> io::Result<Metadata>Working Example
Example Snippetrust
fn main() { use std::fs::{self, File, OpenOptions}; use std::io::{Read, Write}; fs::create_dir("bm-fixture").expect("use a fresh disposable directory"); let p = std::path::Path::new("bm-fixture").join("note.txt"); File::create_new(&p).unwrap().write_all(b"abc").unwrap(); let m = fs::metadata(&p).unwrap(); println!("{} {}", m.is_file(), m.len());}