我正在努力使我的rust lib中的宏可用于其他rust项目。
这是我现在如何尝试完成此工作的示例。
lib.rs
:
#![crate_name = "dsp"]
#![feature(macro_rules, phase)]
#![phase(syntax)]
pub mod macros;
macros.rs
:
#![macro_escape]
#[macro_export]
macro_rules! macro(...)
other_project.rs
:
#![feature(phase, macro_rules)]
#![phase(syntax, plugin, link)] extern crate dsp;
macro!(...) // error: macro undefined: 'macro!'
我在正确的轨道上吗?我一直在尝试使用std :: macros作为参考,但是我似乎运气不高。有什么明显的我想念的吗?
您的属性杂乱无章。
#![…]
指外部范围,而#[…]
指下一项。
以下是一些注意事项:
在中lib.rs
,#![feature(phase)]
是不必要的,并且#![phase(syntax)]
是没有意义的。
在中other_project.rs
,您的phase
属性应用于板条箱,而不应用于extern crate dsp;
项目,这就是为什么它不会从中加载任何宏的原因。删除!
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句