小编Xue*_*eng的帖子

为什么 rustc 允许我泄露私有类型?

我做了一个最小的例子。在lib.rs

mod sealed {
    pub enum Choice {
        A,
        B,
    }
}

pub fn print_choice(choice: sealed::Choice) {
    match choice {
        sealed::Choice::A => println!("Choice A"),
        sealed::Choice::B => println!("Choice B"),
    }
}
Run Code Online (Sandbox Code Playgroud)

我认为:枚举Choice是公共​​的。然而,它处于私人模式中,无法从板条箱外部访问。因此该函数print_choice根本不可调用。

我的想法有什么问题吗?

rust

5
推荐指数
2
解决办法
402
查看次数

标签 统计

rust ×1