如何重新导出枚举?

How can an enum be re-exported?

这给了我一个错误:

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
}

执行此操作的正确方法是什么?

这是一个已知问题,#26264

您应该 pub use foo::T;type 纯粹是一个别名,它的意图是类型的组合和泛型的填充(例如 type Foo = Bar<Baz>;),所以对于 public 重新导出它无论如何都不会做你想要的。