Skip to content

Instantly share code, notes, and snippets.

@flxxyz
Created August 21, 2020 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flxxyz/05a1df87a05601be23a561e5d9b1d205 to your computer and use it in GitHub Desktop.
Save flxxyz/05a1df87a05601be23a561e5d9b1d205 to your computer and use it in GitHub Desktop.
rust 不同系统转换目录路径
pub fn convert_path(path_str: &str) -> String {
if cfg!(target_os = "windows") {
String::from(path_str.replace("\\", "/"))
} else {
String::from(path_str)
}
}
fn main() {
println!("hello world!");
let test_path = String::from("C:\\windows\\system32\\cmd.exe");
println!(convert_path(test_path));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment