Module 如何重新导出枚举?
这给了我一个错误:Module 如何重新导出枚举?,module,rust,Module,Rust,这给了我一个错误: mod foo { pub enum T { Foo, } } mod bar { pub type T = ::foo::T; } fn main() { let _ = bar::T::Foo; // error: no associated item named `Foo` found for type `foo::T` in the current scope } 正确的方法是什么?这是一个已知的问题 您应该pub使用foo::T取而代之
mod foo {
pub enum T {
Foo,
}
}
mod bar {
pub type T = ::foo::T;
}
fn main() {
let _ = bar::T::Foo; // error: no associated item named `Foo` found for type `foo::T` in the current scope
}
正确的方法是什么?这是一个已知的问题
您应该
pub使用foo::T代码>取而代之type
纯粹是一个别名,其目的是类型的组合和泛型的填充(例如type Foo=Bar;
),因此,对于公开的重新导出,它无论如何都不会满足您的要求。请注意,Rust样式是4-空格缩进。@Shepmaster Rust样式很傻:)这实际上是为了填充泛型;实际用例是。很高兴知道这是一个悬而未决的问题,谢谢!同时,我刚刚添加了一个usefoo::T::*代码>