#[import]Expand description
Imports a path anonymously at the top of the decorated function body.
This attribute macro injects use <path> as _; as the first statement of the
function body, bringing trait methods (or other importable items) into scope
without binding a name.
§Usage
use hyperlane_macros::*;
trait Greet {
fn greet(&self) -> &'static str;
}
struct Greeter;
impl Greet for Greeter {
fn greet(&self) -> &'static str {
"hello"
}
}
#[import(crate::Greet)]
fn run() -> &'static str {
Greeter.greet()
}
fn main() {
assert_eq!(run(), "hello");
}The macro accepts a single path and can be applied to any function, regardless
of its signature. The injected import carries #[allow(unused_imports)], so an
unused import is silently ignored instead of being flagged for removal, while an
invalid path still fails to compile:
ⓘ
use hyperlane_macros::*;
#[import(crate::DoesNotExist)]
fn run() {}
fn main() {}§Arguments
TokenStream- The path to import anonymously.TokenStream- The token stream of the item to be processed.
§Returns
TokenStream- The expanded token stream.