std-function
fs::read: read entire file as bytes
Load a small binary file into memory. For large or unbounded data, use a buffered reader and explicit limits. Run only inside a disposable working directory. The fixture must not already exist. Expected stdout (not executed): [0, 255, 7] Common mistake: Treating all file bytes as text.
Formal Syntax & Structure
rust syntaxrust
fs::read(path) -> io::Result<Vec<u8>>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(&[0,255,7]).unwrap(); println!("{:?}", fs::read(&p).unwrap());}