Har*_*aka 5 code-generation compilation rust rust-cargo rust-macros
是否有 Rust 宏或类似的解决方法来包含cargo new
在我的源文件中创建的“src”文件夹的路径作为编译时或具体执行时的字符串文字cargo build
?
我已经成功地完成了类似的操作,用于include_str!
包含文件内容,但我需要知道是否可以直接在代码中包含 src 路径。
不,但您可以使用以下方法接近file!
:
const FILE: &'static str = concat!(env!("CARGO_MANIFEST_DIR"), "/", file!());
fn main() {
use std::path::Path;
println!("FILE: {:?}", FILE);
println!("src path: {:?}", Path::new(FILE).parent());
}
Run Code Online (Sandbox Code Playgroud)
输出,在操场上:
const FILE: &'static str = concat!(env!("CARGO_MANIFEST_DIR"), "/", file!());
fn main() {
use std::path::Path;
println!("FILE: {:?}", FILE);
println!("src path: {:?}", Path::new(FILE).parent());
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2147 次 |
最近记录: |