tokio/fs/try_exists.rs
1use crate::fs::asyncify;
2
3use std::io;
4use std::path::Path;
5
6/// Returns `Ok(true)` if the path points at an existing entity.
7///
8/// This function will traverse symbolic links to query information about the
9/// destination file. In case of broken symbolic links this will return `Ok(false)`.
10///
11/// This is the async equivalent of [`std::path::Path::try_exists`][std].
12///
13/// [std]: fn@std::path::Path::try_exists
14///
15/// # Examples
16///
17/// ```no_run
18/// use tokio::fs;
19///
20/// # async fn dox() -> std::io::Result<()> {
21/// fs::try_exists("foo.txt").await?;
22/// # Ok(())
23/// # }
24/// ```
25pub async fn try_exists(path: impl AsRef<Path>) -> io::Result<bool> {
26 let path = path.as_ref().to_owned();
27 asyncify(move || path.try_exists()).await
28}