From c333e881c4e2fafc63ac42f0b85a0ba4b74d4077 Mon Sep 17 00:00:00 2001 From: Hosssein Date: Sun, 10 Dec 2023 12:13:00 +0330 Subject: [PATCH] Update the example in fs.md to ensure compatibility with both Windows and Unix-type systems. --- src/std_misc/fs.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/std_misc/fs.md b/src/std_misc/fs.md index 48e4d4d66a..e078e36edc 100644 --- a/src/std_misc/fs.md +++ b/src/std_misc/fs.md @@ -7,7 +7,10 @@ use std::fs; use std::fs::{File, OpenOptions}; use std::io; use std::io::prelude::*; +#[cfg(target_os = "unix")] use std::os::unix; +#[cfg(target_os = "windows")] +use std::os::windows; use std::path::Path; // A simple implementation of `% cat path` @@ -62,11 +65,16 @@ fn main() { println!("`ln -s ../b.txt a/c/b.txt`"); // Create a symbolic link, returns `io::Result<()>` - if cfg!(target_family = "unix") { + #[cfg(target_os = "unix")] { unix::fs::symlink("../b.txt", "a/c/b.txt").unwrap_or_else(|why| { println!("! {:?}", why.kind()); }); } + #[cfg(target_os = "windows")] { + windows::fs::symlink_file("../b.txt", "a/c/b.txt").unwrap_or_else(|why| { + println!("! {:?}", why.to_string()); + }); + } println!("`cat a/c/b.txt`"); match cat(&Path::new("a/c/b.txt")) {