Macros 如何在隐式导出宏时使用模块中定义的构造

Macros 如何在隐式导出宏时使用模块中定义的构造,macros,rust,Macros,Rust,正在尝试从模块导出宏。宏生成实现模块中定义的某些特性的结构。有没有一种方法可以在不手动导入宏的情况下获取宏? 错误消息更改为“下一步”: tests\test_simple.rs:8:13: 8:29 error: no associated item named `new` found for type `Test<i32>` in the current scope tests\test_simple.rs:8 let a = Test::<i32>::ne

正在尝试从模块导出宏。宏生成实现模块中定义的某些特性的结构。有没有一种方法可以在不手动导入宏的情况下获取宏?

错误消息更改为“下一步”:

tests\test_simple.rs:8:13: 8:29 error: no associated item named `new` found for type `Test<i32>` in the current scope
tests\test_simple.rs:8     let a = Test::<i32>::new(1);
                               ^~~~~~~~~~~~~~~~
tests\test_simple.rs:8:13: 8:29 help: items from traits can only be used if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
tests\test_simple.rs:8:13: 8:29 help: candidate #1: use `macro_test::B`
tests\test\u simple.rs:8:13:8:29错误:在当前作用域中找不到类型为“test”的名为“new”的关联项
tests\test_simple.rs:8让a=test:::新(1);
^~~~~~~~~~~~~~~~
tests\test\u simple.rs:8:13:8:29帮助:traits中的项目只能在traits在范围内时使用;以下特性已实现,但不在范围内,可能需要为其添加一个“use”:
tests\test_simple.rs:8:13:8:29帮助:候选者#1:使用'macro_test::B'`

为什么会发生这种情况?

因为如果不
使用
调用trait方法,就不能调用trait方法。这与宏无关,这只是Rust中的标准规则

也许您希望宏生成一个固有的impl?i、 e

impl$n其中T:Copy{
新发布(x:T)->Self{
$n{x:x}
}
}

而不是您目前拥有的。

不幸的是,在这种情况下不是。这只是一个合成示例,但在工作代码中是不可能的。嗯,谢谢你的回答,这说明我错了。
<macro_test macros>:2:54: 2:61 error: use of undeclared trait name `B` [E0405]
<macro_test macros>:2 struct $ n < T > where T : Copy { x : T } impl < T > B < T > for $ n < T >
impl<T> $crate::B<T> for $n<T> where T: Copy {
tests\test_simple.rs:8:13: 8:29 error: no associated item named `new` found for type `Test<i32>` in the current scope
tests\test_simple.rs:8     let a = Test::<i32>::new(1);
                               ^~~~~~~~~~~~~~~~
tests\test_simple.rs:8:13: 8:29 help: items from traits can only be used if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
tests\test_simple.rs:8:13: 8:29 help: candidate #1: use `macro_test::B`