tokio
tokio copied to clipboard
Add `fs::try_exists`
Motivation
std
has added Path::exists
and (unstable) fs::try_exists
. Adding try_exists
to tokio::fs
based on prior discussions in #3375 (which has not been updated for a while)
Solution
Add fs::try_exists
function.
Fixes: #3373
Let's wait for std to stabilize try_exists
. I'd rather not stabilize this, then see std change the signature of theirs so we don't match.
try_exists
has now been stabilized in std https://github.com/rust-lang/rust/pull/97912.
Perhaps this should be revisited?
Sure! I see that it hasn't been released yet, but I would be happy to include our own version of it when that happens.
Unless I'm misunderstanding looks like std::path::try_exists
has been stabilized? https://github.com/rust-lang/rust/commit/77316a4aaa0029481397ff2e43f57e60d5226569
Would you folks find it helpful if I contributed a version using Path::try_exists
?
Well, the documentation for fs::try_exists
still says "This is a nightly-only experimental API". Once that changes, I would be happy with adding it to Tokio.
Didn't realize there are more updates on this PR after 2 years. I can still update this PR to make it work with the latest Tokio version once the API is stablized.
Ah, I see. It's been stabilized as Path::try_exists
. That's an interesting situation because we don't have a Path
type in Tokio. In that case, I am ok with adding an tokio::fs::try_exists
as a replacement, since we cannot mirror what std is doing.
It seems that minrust is installing Rust 1.49.0 which is too hold for the feature? (at 1.63.0, already >= 6 months old) Can I update it in the ci.yml file?
As an outside contributor, I would personally consider that to be a breaking change and vote for something that will work with Rust 1.49, if possible. From a quick search I found this: https://stackoverflow.com/questions/32384594/how-to-check-whether-a-path-exists
But some may not agree with me.
See https://doc.rust-lang.org/cargo/reference/semver.html#env-new-rust
https://stackoverflow.com/questions/32384594/how-to-check-whether-a-path-exists
The was actually originally used in the implementation (before my recent sync). I can consider reverting it back if deemed better to use fs::metadata
Ah, yes, we need to use an implementation that will work on 1.49. Sorry if that was unclear. My main concern was matching the API in std, but it turns out that they have chosen an API we cannot match, so I am ok with moving forward with an fs::try_exists
instead.
Updated implementation to use the exact fs::try_exists impl from std
Updated implementation to use the exact fs::try_exists impl from std
Another outsider comment I would kinda favor adding a comment with this info.
P.S. +1 on the explanatory comment added thanks!
Looks great! Thanks so much!
🙌🏻