use std::fs::File;
use std::io::{Write, Read, Seek, SeekFrom};
use std::path::Path;
fn main() {
// Write
let mut tmpfile: File = tempfile::tempfile().unwrap();
write!(tmpfile, "Hello World!").unwrap();
println!("{}", tempfile.abspath); // ??? How to get the absolute path?
}
A File does not know its own path. This is because it is a thin wrapper around a file descriptor, and there isn't necessarily a canonical path for every file descriptor. In particular, tempfile() removes the file from the filesystem after opening it, so it does not exist at any path.
The std::fs::File returned from tempfile::tempfile() points to a file which has been "unlinked" from the filesystem, making it inaccessible to all external processes. That means other programs won't be able to monitor it. When the File is dropped or the process exits, the OS will automatically garbage collect the data because it is no longer used by the filesystem or any process.
You should probably be more specific when you say "monitor", too. I'm guessing you just want to see the file's contents (kinda like tail -f path/to/file.txt), in which case you should create a NamedTempFile as mentioned earlier.