bytecodealliance / bytecodealliance/cap-std

Create directory if not exists, and return `Dir`

オープン
#372 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Rust
スター
821
フォーク
57
平均マージ
1時間 16分
マージ済み PR(30日)
4

説明

Is there a simple way to create a directory if it does not yet exist and to return the `Dir`?

Something along the lines of:

```rs
async fn create_dir(parent: &Dir, path: &str) -> anyhow::Result {
match parent.create_dir(path) {
Ok(_) => {}
Err(e) => match e.kind() {
std::io::ErrorKind::AlreadyExists => {}
_ => {
Err(e)?;
}
},
}
Ok(parent.open_dir(path).await?) // could maybe be a TOCTOU?
}
```

I couldn't find a `create_dir_with` that would allow specifying e.g. `OpenOptions`, and all the create_dir functions don't return the `Dir` itself.

If not, would the project be open to contributions on this?

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。