std-method

OpenOptions::append: append writes

Open for appending rather than overwriting at a chosen offset. Multiple calls or writers need their own record-level coordination. Run only inside a disposable working directory. The fixture must not already exist. Expected stdout (not executed): AB Common mistake: Assuming multiple append calls form one atomic record.

Formal Syntax & Structure

rust syntaxrust
OpenOptions::new().append(true).open(path)

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"A").unwrap();    OpenOptions::new().append(true).open(&p).unwrap().write_all(b"B").unwrap();    println!("{}", fs::read_to_string(&p).unwrap());}
Rust Reference