OS std::fs::OpenOptions 上的错误 87 "The parameter is incorrect."

OS error 87 "The parameter is incorrect." on std::fs::OpenOptions

std::fs::OpenOptions .open() 在我下载一个 crate directories 之前工作正常 。我已经尝试删除 .toml 依赖项并更改项目,但使用 OpenOptions 仍然收到相同的错误。使用 std::fs::File .create() .open() 似乎工作得很好。

这是输出:Err(Os { code: 87, kind: InvalidInput, message: "The parameter is incorrect." })

新项目中用于测试的确切代码。

fn main() {
    let r = std::fs::OpenOptions::new()
        .create_new(true)
        .open("foo.txt");
    println!("What is this bug: {:?}", r);
}

Rust 版本 1.59.0

The file must be opened with write or append access in order to create a new file. -- create_new docs

这个有效:

fn main() {
    let r = std::fs::OpenOptions::new()
        .create_new(true).write(true)
        .open("foo.txt");
    println!("What is this bug: {:?}", r);
}