std-module
std::fs: local filesystem operations
The filesystem module creates, reads and inspects files and directories. Unlike lexical paths, these calls access OS-managed state. Run only inside a disposable working directory. The fixture must not already exist. Expected stdout (not executed): hello Common mistake: Ignoring a Result from an operation that may fail.
Formal Syntax & Structure
rust syntaxrust
use std::fs;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"hello").unwrap(); println!("{}", fs::read_to_string(&p).unwrap());}