Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Linux, no Windows path to Linux? #7

Closed
picobyte opened this issue Jul 14, 2021 · 1 comment
Closed

On Linux, no Windows path to Linux? #7

picobyte opened this issue Jul 14, 2021 · 1 comment

Comments

@picobyte
Copy link
Contributor

picobyte commented Jul 14, 2021

On my Linux I cannot seem to convert a Windows path to a Linux path via path-slash, why is this not supported? I have a use-case where this make sense, trying to concatenate a relative path usually specified in windows path format, to a Linux root path.

use path_slash::PathExt;
use std::path::Path;

fn main() {
    let pre = r"FOMod\CBBE.png";
    println!("{}", pre);

    let path = Path::new(pre);
    println!("1: {}", path.display());

    // suggested in the docs, but does not work either:
    println!("2: {}", PathBuf::from(pre).display());
    let supposedly_slashed = path.to_slash().unwrap();

    println!("3: {}", supposedly_slashed);

    let works = path::PathBuf::from_backslash(pre);
    println!("4: {}", works.display());
}

output (no. 4 works, but only after my pull request)

FOMod\CBBE.png
1: FOMod\CBBE.png
2: FOMod\CBBE.png
3: FOMod\CBBE.png
4: FOMod/CBBE.png

Then aren't the crate and function misnomers? Path-backslash, and to_backslash() would indicate what to expect.

Linux 5.12.15-arch1-1 #1 SMP PREEMPT x86_64 GNU/Linux
rustc 1.55.0-nightly (3e1c75c6e 2021-07-13)
path-slash = "0.1.4"

on Linux it is possible to create a directory with a backslash mkdir "foo\\bar" so maybe some behavior in PathBuf was adapted. I've added a pull request #8 to add from_backslash() functions, which should hopefully do the job.

@rhysd
Copy link
Owner

rhysd commented Jul 4, 2022

This was fixed by #8. Closing.

@rhysd rhysd closed this as completed Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants