如何使用Rust来检测操作系统类型? [英] How can one detect the OS type using Rust?
本文介绍了如何使用Rust来检测操作系统类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用Rust检测操作系统类型?我需要指定特定于操作系统的默认路径.应该使用条件编译吗?
How can one detect the OS type using Rust? I need to specify a default path specific to the OS. Should one use conditional compilation?
例如:
#[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!
语法扩展名.
You can also use cfg!
syntax extension.
if cfg!(windows) {
println!("this is windows");
} else if cfg!(unix) {
println!("this is unix alike");
}
这篇关于如何使用Rust来检测操作系统类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文