如何重新导出枚举?

bfo*_*ops 2 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
}
Run Code Online (Sandbox Code Playgroud)

这样做的正确方法是什么?

Chr*_*gan 5

这是一个已知问题,#26264.

你应该pub use foo::T;改为.type纯粹是一个别名,其意图是类型的组合和填充泛型(例如type Foo = Bar<Baz>;),所以对于公共再出口它不会做你想要的任何事情.