How to use external crates with our macros in Rust

What is a macro exactly?

Fundamentally, macros are a way of writing code that writes other code, which is known as metaprogramming.

Expansion is a relatively simple affair. At some point after the construction of the AST, but before the compiler begins constructing its semantic understanding of the program, it will expand all macros.

Why using external crate is not so simple?

pub extern crate other_crate;
$crate::other_crate::extern_function();
::my_crate::other_crate::extern_function();

Conclusion

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store