Skip to main content

parsley_rs_hack/
lib.rs

1#[cfg(any(target_os = "macos", windows, target_os = "linux"))]
2pub fn source_string(f: &std::fs::File) -> String {
3    use filepath::FilePath;
4    use url::Url;
5    match f.path() {
6        Ok(path) => match Url::from_file_path(&path) {
7            Ok(url) => url.to_string(),
8            Err(_) => path.display().to_string(),
9        },
10        Err(_) => {
11            #[cfg(unix)]
12            {
13                use std::os::unix::io::AsRawFd;
14                format!("File Descriptor: {:x}", f.as_raw_fd())
15            }
16            #[cfg(windows)]
17            {
18                use std::os::windows::io::AsRawHandle;
19                format!("File Handle: {:p}", f.as_raw_handle())
20            }
21        }
22    }
23}
24
25#[cfg(not(any(target_os = "macos", windows, target_os = "linux")))]
26pub fn source_string(f: &std::fs::File) -> String {
27    use std::os::unix::io::AsRawFd;
28    format!("File Descriptor: {:x}", f.as_raw_fd())
29}