Hi, I am a coder new to Rust.
I am using std::fs::OpenOptions::new() .write(true) .create_new(true) .open(path)
to create a new file without overwriting any old files by mistake. I also want to handle the "file already exits" error separately from any other unforeseeable case.
The error I get from trying to create_new on an existing file with {:?} is Error { repr: Os { code: 80, message: "The file exists." } }
. However, error.kind() returns io::ErrorKind::Other
not io::ErrorKind::AlreadyExists
as I expected. I assume the Os error code 80 is windows only and ErrorKind is the cross platform way to work on errors, so is this a bug or missing feature in the std?
my setup:
rustc -Vv
rustc 1.9.0 (e4e8b6668 2016-05-18)
binary: rustc
commit-hash: e4e8b666850a763fdf1c3c2c142856ab51e32779
commit-date: 2016-05-18
host: i686-pc-windows-msvc
release: 1.9.0
rustc --print cfg
target_os="windows"
target_family="windows"
target_arch="x86"
target_endian="little"
target_pointer_width="32"
target_env="msvc"
windows
debug_assertions