如何使用Rust检测OS类型?我需要指定一个特定于操作系统的默认路径。应该使用条件编译吗?在Rust中检测平台
例如:
#[cfg(target_os = "macos")]
static DEFAULT_PATH: &str = "path2";
#[cfg(target_os = "linux")]
static DEFAULT_PATH: &str = "path0";
#[cfg(target_os = "windows")]
static DEFAULT_PATH: &str = "path1";
“*应该使用条件编译吗?*” - 是的。 –
根据你需要什么样的默认路径,可能已经有一个箱子,所以你不需要自己编写'#[cfg]'。 – kennytm