我有以下目录结构
/main.rs
/lib.rs
/tutorial/mod.rs
/tutorial/foo.rs
在foo.rs
我需要使用glium库中的宏,implement_vertex!
.如果我放在#[macro_use] extern crate glium;
头上foo.rs
,我会得到一个error: an `extern crate` loading macros must be at the crate root
.我也得到了error: macro undefined: 'implement_vertex!'
还有一个lib.rs
是教程模块的包根.我需要放在#[macro_use]
那里.如果我同时拥有它们main.rs
,这会创建2个箱子根lib.rs
吗?
在子模块中导入宏的正确方法是什么?
小智 14
宏在编译阶段足够早地处理,命令很重要.你和我一样,可能已经变得很好并习惯了Rust,因为需要关心你的使用顺序和crate声明.
根据需要将#[macro_use] extern crate glium;
语句移动到您lib.rs
和/或main.rs
文件的顶部.
就像编译器告诉您的那样:
an `extern crate` loading macros must be at the crate root
将放在您的情况下#[macro_use] extern crate glium;
的板条箱根main.rs
中。确保extern crate
语句在语句之前mod
,否则模块将无法访问导入的宏。
然后,您可以在子模块中使用该宏。
归档时间: |
|
查看次数: |
7757 次 |
最近记录: |