Expand description
The difference between ::core::include!
and this version
of the macro is that, due to limitations of proc-macros in stable Rust,
it is not possible to know whence a macro is called.
Thus, this macro requires it be called with a path that starts
from the “root” of the package, i.e., a path that will be interpreted
as if it started from: concat!(env!("CARGO_MANIFEST_DIR"), "/")
.
Example
use ::with_builtin_macros::with_builtin;
macro_rules! metamancy {(
$use_stmt:item
$macro_def_item:item
#[cfg(any())]
mod to_be_expanded { $foo_fn:item }
$main_fn:item
$macro_call:item
) => (
$foo_fn
)}
#[cfg(any())]
mod to_be_expanded {
fn foo ()
{}
}
fn main ()
{
foo();
}
with_builtin!(let $this_file = include_from_root!("src/main.rs") in {
metamancy!($this_file);
});