Skip to content

Commit 933c339

Browse files
authored
Merge pull request #1777 from HosseinAssaran/patch-1
Update the example in fs.md to ensure compatibility with both Window and Unix-type systems.
2 parents da0a06a + c333e88 commit 933c339

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Diff for: src/std_misc/fs.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use std::fs;
77
use std::fs::{File, OpenOptions};
88
use std::io;
99
use std::io::prelude::*;
10+
#[cfg(target_os = "unix")]
1011
use std::os::unix;
12+
#[cfg(target_os = "windows")]
13+
use std::os::windows;
1114
use std::path::Path;
1215
1316
// A simple implementation of `% cat path`
@@ -62,11 +65,16 @@ fn main() {
6265
6366
println!("`ln -s ../b.txt a/c/b.txt`");
6467
// Create a symbolic link, returns `io::Result<()>`
65-
if cfg!(target_family = "unix") {
68+
#[cfg(target_os = "unix")] {
6669
unix::fs::symlink("../b.txt", "a/c/b.txt").unwrap_or_else(|why| {
6770
println!("! {:?}", why.kind());
6871
});
6972
}
73+
#[cfg(target_os = "windows")] {
74+
windows::fs::symlink_file("../b.txt", "a/c/b.txt").unwrap_or_else(|why| {
75+
println!("! {:?}", why.to_string());
76+
});
77+
}
7078
7179
println!("`cat a/c/b.txt`");
7280
match cat(&Path::new("a/c/b.txt")) {

0 commit comments

Comments
 (0)