Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.