Skip to content

Instantly share code, notes, and snippets.

@octplane
Created August 30, 2015 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save octplane/cc39bb26c0c6d445e317 to your computer and use it in GitHub Desktop.
Save octplane/cc39bb26c0c6d445e317 to your computer and use it in GitHub Desktop.
use std::io::Write;
use std::fs::OpenOptions;
use std::path::{ Path};
use std::thread;
fn main() {
let dst = Path::new("./test.txt");
let mut file = OpenOptions::new().write(true).create(true).open(dst).unwrap();
file.write_all(b"create").unwrap();
file.flush().unwrap();
drop(file);
thread::sleep_ms(1000); // Wait a while after create above before observing.
let mut file2 = OpenOptions::new().write(true).append(true).open(dst).unwrap();
file2.write_all(b"foo").unwrap();
file2.flush().unwrap();
drop(file2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment