Skip to content

Commit

Permalink
Update the example in fs.md to ensure compatibility with both Windows…
Browse files Browse the repository at this point in the history
… and Unix-type systems.
  • Loading branch information
HosseinAssaran committed Dec 10, 2023
1 parent da0a06a commit c333e88
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/std_misc/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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")) {
Expand Down

0 comments on commit c333e88

Please sign in to comment.