std-function
fs::read_link: read the stored link target
Return the stored target of a symbolic link, not a resolved absolute path. The target may not exist. Unix fixture only. Use a fresh disposable working directory exclusively controlled by this program. Expected stdout (not executed): missing.txt Common mistake: Assuming a successfully read link target exists.
Formal Syntax & Structure
rust syntaxrust
fs::read_link(path) -> io::Result<PathBuf>Working Example
Example Snippetrust
fn main() { use std::fs::{self, File}; use std::io::{Read, Write}; fs::create_dir("bm-fixture").expect("fresh working directory required"); let p = std::path::Path::new("bm-fixture").join("note.txt"); let q = p.with_file_name("alias"); std::os::unix::fs::symlink("missing.txt", &q).unwrap(); println!("{}", fs::read_link(q).unwrap().to_str().unwrap());}