Skip to content

Commit c333e88

Browse files
Update the example in fs.md to ensure compatibility with both Windows and Unix-type systems.
1 parent da0a06a commit c333e88

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/std_misc/fs.md

Lines changed: 9 additions & 1 deletion
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)