Compilation 是否有宏或类似的解决方法在编译时包含源文件夹(src)路径?

Compilation 是否有宏或类似的解决方法在编译时包含源文件夹(src)路径?,compilation,rust,code-generation,rust-cargo,rust-macros,Compilation,Rust,Code Generation,Rust Cargo,Rust Macros,是否有一个Rust宏或类似的解决方法,可以在编译时或执行货物构建时,将通过cargo new在我的源文件中创建的“src”文件夹的路径作为字符串文字包含在内 我已经成功地做了类似的事情,我使用了include\u str包含文件内容,但我需要知道是否可以在代码中直接包含src路径 没有,但您可以通过以下方式接近: 输出: 文件:“/playerly/src/main.rs” src路径:一些(“/playder/src”) const FILE: &'static str = conc

是否有一个Rust宏或类似的解决方法,可以在编译时或执行
货物构建时,将通过
cargo new
在我的源文件中创建的“src”文件夹的路径作为字符串文字包含在内


我已经成功地做了类似的事情,我使用了
include\u str包含文件内容,但我需要知道是否可以在代码中直接包含src路径

没有,但您可以通过以下方式接近:

输出:

文件:“/playerly/src/main.rs”
src路径:一些(“/playder/src”)
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());
}