async_std/fs/symlink_metadata.rs
1use crate::fs::Metadata;
2use crate::io;
3use crate::path::Path;
4use crate::task::spawn_blocking;
5
6/// Reads metadata for a path without following symbolic links.
7///
8/// If you want to follow symbolic links before reading metadata of the target file or directory,
9/// use [`metadata`] instead.
10///
11/// This function is an async version of [`std::fs::symlink_metadata`].
12///
13/// [`metadata`]: fn.metadata.html
14/// [`std::fs::symlink_metadata`]: https://doc.rust-lang.org/std/fs/fn.symlink_metadata.html
15///
16/// # Errors
17///
18/// An error will be returned in the following situations:
19///
20/// * `path` does not point to an existing file or directory.
21/// * The current process lacks permissions to read metadata for the path.
22/// * Some other I/O error occurred.
23///
24/// # Examples
25///
26/// ```no_run
27/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
28/// #
29/// use async_std::fs;
30///
31/// let perm = fs::symlink_metadata("a.txt").await?.permissions();
32/// #
33/// # Ok(()) }) }
34/// ```
35pub async fn symlink_metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
36 let path = path.as_ref().to_owned();
37 spawn_blocking(move || std::fs::symlink_metadata(path)).await
38}