Coverage Report

Created: 2025-02-25 06:39

/rust/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/fs/metadata.rs
Line
Count
Source (jump to first uncovered line)
1
use crate::fs::asyncify;
2
3
use std::fs::Metadata;
4
use std::io;
5
use std::path::Path;
6
7
/// Given a path, queries the file system to get information about a file,
8
/// directory, etc.
9
///
10
/// This is an async version of [`std::fs::metadata`].
11
///
12
/// This function will traverse symbolic links to query information about the
13
/// destination file.
14
///
15
/// # Platform-specific behavior
16
///
17
/// This function currently corresponds to the `stat` function on Unix and the
18
/// `GetFileAttributesEx` function on Windows.  Note that, this [may change in
19
/// the future][changes].
20
///
21
/// [changes]: https://doc.rust-lang.org/std/io/index.html#platform-specific-behavior
22
///
23
/// # Errors
24
///
25
/// This function will return an error in the following situations, but is not
26
/// limited to just these cases:
27
///
28
/// * The user lacks permissions to perform `metadata` call on `path`.
29
/// * `path` does not exist.
30
///
31
/// # Examples
32
///
33
/// ```rust,no_run
34
/// use tokio::fs;
35
///
36
/// #[tokio::main]
37
/// async fn main() -> std::io::Result<()> {
38
///     let attr = fs::metadata("/some/file/path.txt").await?;
39
///     // inspect attr ...
40
///     Ok(())
41
/// }
42
/// ```
43
0
pub async fn metadata(path: impl AsRef<Path>) -> io::Result<Metadata> {
44
0
    let path = path.as_ref().to_owned();
45
0
    asyncify(|| std::fs::metadata(path)).await
46
0
}