2 个版本
| 0.1.1 | 2018 年 11 月 19 日 |
|---|---|
| 0.1.0 | 2018 年 10 月 26 日 |
1779 在 Rust 模式 中
每月 68 次下载
在 2 个crate 中使用
7KB
获取您操作系统的路径分隔符
当您想要 include!(_) 生成文件时,cargo 会要求您将它们放在 $OUT_DIR 中。然而,"常规"的方式在
include!(concat!(env!("OUT_DIR"), "/somefile.rs"));
在某些 Windows 系统上会失败,因为它们无法理解 / 路径分隔符。此 crate 允许您将其替换为
include!(join_path!(env!("OUT_DIR"), "somefile.rs"));
这将适用于所有操作系统。您可以通过在 / 上前缀 join_path! 参数来创建以分隔符开始的路径
join_path!(/ "usr", "local", "lib");
用法
将其添加到您的 Cargo.toml 中
pathsep = "0.1"
然后您可以在 crate 根目录中使用 #[macro_use] extern crate pathsep;。从 Rust 1.30 开始,您也可以直接省略 #[macro_use] 和 use pathsep::join_path;。
许可证
本代码根据 Apache 许可证 2.0 或 MIT 许可证条款许可,由您自行选择。
lib.rs:
一个小型宏,提供目标系统的路径分隔符
这可以与 include!(..) 或 include_str!(..) 和 concat!(..) 一起使用来构建路径。
示例
#[macro_use] extern crate pathsep;
include!(concat!(env!("OUT_DIR"), path_separator!(), "generated.rs"));
可以更简洁地写成
#[macro_use] extern crate pathsep;
include!(path_join!(env!("OUT_DIR"), "generated.rs"));