async_std/os/windows/
fs.rs

1//! Windows-specific filesystem extensions.
2
3use crate::io;
4use crate::path::Path;
5use crate::task::spawn_blocking;
6
7/// Creates a new directory symbolic link on the filesystem.
8///
9/// The `dst` path will be a directory symbolic link pointing to the `src` path.
10///
11/// This function is an async version of [`std::os::windows::fs::symlink_dir`].
12///
13/// [`std::os::windows::fs::symlink_dir`]: https://doc.rust-lang.org/std/os/windows/fs/fn.symlink_dir.html
14///
15/// # Examples
16///
17/// ```no_run
18/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
19/// #
20/// use async_std::os::windows::fs::symlink_dir;
21///
22/// symlink_dir("a", "b").await?;
23/// #
24/// # Ok(()) }) }
25/// ```
26pub async fn symlink_dir<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> {
27    let src = src.as_ref().to_owned();
28    let dst = dst.as_ref().to_owned();
29    spawn_blocking(move || std::os::windows::fs::symlink_dir(&src, &dst)).await
30}
31
32/// Creates a new file symbolic link on the filesystem.
33///
34/// The `dst` path will be a file symbolic link pointing to the `src` path.
35///
36/// This function is an async version of [`std::os::windows::fs::symlink_file`].
37///
38/// [`std::os::windows::fs::symlink_file`]: https://doc.rust-lang.org/std/os/windows/fs/fn.symlink_file.html
39///
40/// # Examples
41///
42/// ```no_run
43/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
44/// #
45/// use async_std::os::windows::fs::symlink_file;
46///
47/// symlink_file("a.txt", "b.txt").await?;
48/// #
49/// # Ok(()) }) }
50/// ```
51pub async fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> {
52    let src = src.as_ref().to_owned();
53    let dst = dst.as_ref().to_owned();
54    spawn_blocking(move || std::os::windows::fs::symlink_file(&src, &dst)).await
55}