15个版本
0.1.18 | 2023年9月9日 |
---|---|
0.1.17 | 2023年4月18日 |
0.1.16 | 2022年5月8日 |
0.1.14 | 2022年3月17日 |
0.1.11 | 2021年5月5日 |
2484 在 Rust 模式
6,329 每月下载次数
用于 28 个crate (12 直接)
28KB
511 行
Manifest Dir Macros
此crate提供类似于函数的宏,用于在编译时检查或操作相对于 CARGO_MANIFEST_DIR 的路径。
示例
#[macro_use] extern crate manifest_dir_macros;
println!(path!("Cargo.toml"));
println!(path!("src/lib.rs"));
println!(path!("src", "lib.rs"));
println!(path!("src", "lib.rs", "/bin"));
println!(path!("/usr"));
println!(exist_path!("Cargo.toml"));
println!(directory_path!("src"));
println!(not_directory_path!("Cargo.toml"));
println!(file_path!("Cargo.toml"));
println!(relative_path!("Cargo.toml"));
println!(directory_relative_path!("src"));
println!(not_directory_relative_path!("Cargo.toml"));
println!(file_relative_path!("Cargo.toml"));
println!(get_file_name!("src/lib.rs"));
println!(get_file_name!(default = "main.rs", "/"));
println!(get_file_stem!("src/lib.rs"));
println!(get_file_stem!(default = "lib", "/"));
println!(get_extension!("src/lib.rs"));
println!(get_extension!(default = "rs", "src/lib"));
println!(get_parent!("src/lib.rs"));
println!(get_parent!(default = "/home", "/"));
#[cfg(feature = "mime_guess")]
{
println!(mime_guess!("src/lib.rs"));
println!(mime_guess!(default = "application/octet-stream", "Cargo.lock"));
}
// The `tuple` feature lets these macros above support to input nested literal string tuples, which is useful when you want to use these macros inside a `macro_rule!` macro and concatenate with other literal strings.
// `$x:expr` matchers can be used in these macros thus.
#[cfg(feature = "tuple")]
{
println!(path!(("foo",)));
println!(path!(("foo", "bar")));
println!(path!("a", ("foo", "bar")));
println!(path!(("foo", "bar"), "a"));
println!(path!(("foo", "bar"), ("a", "b")));
println!(path!(("foo", "bar", ("a", "b")), ("c", "d")));
}
Crates.io
https://crates.io/crates/manifest-dir-macros
文档
https://docs.rs/manifest-dir-macros
许可
依赖
~0.3–0.9MB
~20K SLoC