如何在Rust中导入宏? [英] How to import macros in Rust?

查看:758
本文介绍了如何在Rust中导入宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力从外部包装箱中导入宏.在我的main.rs中,我要导入Glium板条箱:

I'm struggling with how to import macros from an external crate. In my main.rs I'm importing the Glium crate:

#![macro_use]
extern crate glium;

pub use glium::*;

// where my actual main function will be done from
mod part01drawtriangle;

fn main() {
    part01drawtriangle::main();
}

在我主要功能来自的另一个文件中,我从该板条箱中调用了一个宏:

In my other file, where my main function is coming from, I call one of the macros from that crate:

pub fn main() {
    implement_vertex!(Vertex, position);
}

在构建时,出现错误消息:

When building, I get the error message:

error: macro undefined: 'implement_vertex!'

推荐答案

#[macro_use],而不是#![macro_use].

#[..]将属性应用于其后的事物(在本例中为extern crate). #![..]将一个属性应用于包含 的事物(在本例中为根模块).

#[..] applies an attribute to the thing after it (in this case, the extern crate). #![..] applies an attribute to the containing thing (in this case, the root module).

这篇关于如何在Rust中导入宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆