-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fs::exists
function
#3375
Add fs::exists
function
#3375
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,27 @@ | ||||||||
use std::path::Path; | ||||||||
|
||||||||
/// Returns `true` if the path points at an existing entity. | ||||||||
/// | ||||||||
/// This function will traverse symbolic links to query information about the | ||||||||
/// destination file. | ||||||||
/// | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
/// # Examples | ||||||||
/// | ||||||||
/// ```rust,no_run | ||||||||
/// # use tokio::fs; | ||||||||
/// | ||||||||
/// # #[tokio::main] | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The example in |
||||||||
/// # async fn main() { | ||||||||
/// let exists = fs::exists("/some/file/path.txt").await; | ||||||||
/// // in case the `/some/file/path.txt` points to existing path | ||||||||
/// assert_eq!(exists, true); | ||||||||
/// # } | ||||||||
/// ``` | ||||||||
/// | ||||||||
/// # Note | ||||||||
/// | ||||||||
/// This method returns false in case of errors thus ignoring them. Use [`fs::metadata`][super::metadata()] | ||||||||
/// if you want to check for errors. | ||||||||
pub async fn exists(path: impl AsRef<Path>) -> bool { | ||||||||
super::metadata(&path).await.is_ok() | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Why not directly use the |
||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.