1 use crate::fs::asyncify; 2 3 use std::io; 4 use std::path::Path; 5 6 /// Creates a new hard link on the filesystem. 7 /// 8 /// This is an async version of [`std::fs::hard_link`]. 9 /// 10 /// The `dst` path will be a link pointing to the `src` path. Note that systems 11 /// often require these two paths to both be located on the same filesystem. 12 /// 13 /// # Platform-specific behavior 14 /// 15 /// This function currently corresponds to the `link` function on Unix 16 /// and the `CreateHardLink` function on Windows. 17 /// Note that, this [may change in the future][changes]. 18 /// 19 /// [changes]: https://doc.rust-lang.org/std/io/index.html#platform-specific-behavior 20 /// 21 /// # Errors 22 /// 23 /// This function will return an error in the following situations, but is not 24 /// limited to just these cases: 25 /// 26 /// * The `src` path is not a file or doesn't exist. 27 /// 28 /// # Examples 29 /// 30 /// ```no_run 31 /// use tokio::fs; 32 /// 33 /// #[tokio::main] 34 /// async fn main() -> std::io::Result<()> { 35 /// fs::hard_link("a.txt", "b.txt").await?; // Hard link a.txt to b.txt 36 /// Ok(()) 37 /// } 38 /// ``` hard_link(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()>39pub async fn hard_link(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> { 40 let src = src.as_ref().to_owned(); 41 let dst = dst.as_ref().to_owned(); 42 43 asyncify(move || std::fs::hard_link(src, dst)).await 44 } 45