【问题标题】:How to get the executable extension across platforms in Rust?如何在 Rust 中跨平台获取可执行扩展?
【发布时间】:2016-12-01 18:23:26
【问题描述】:

我正在编写可移植的 Rust 代码以在某些目录中查找程序。在 Windows 上,我希望它是 foo.exe,而在其他地方只是 foo

显然我可以使用if cfg!(windows),但这看起来很难看。

有没有更好的方法来查找平台的可执行文件扩展名?

【问题讨论】:

    标签: windows path rust filenames


    【解决方案1】:

    是的,std::env::consts::EXE_SUFFIX 在 Windows 上将是 .exestd::env::consts::EXE_EXTENSION 将是 exe。在 Unix 上两者都是空的。

    这些可以与基本名称结合使用,例如std::path::PathBuf::set_extension

    【讨论】:

      猜你喜欢
      • 2015-12-18
      • 1970-01-01
      • 1970-01-01
      • 2017-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-24
      • 1970-01-01
      相关资源
      最近更新 更多