什么是#[警告(不稳定)]关于Rust?

weg*_*gry 13 io rust

我有一个非常简单的cat函数,用Rust 1.0 alpha编写.

use std::io;

fn main(){
    let mut reader = io::stdin();
    loop {
        let input = reader.read_line().ok().expect("Failed to read line");
        print!("{}", input);
    }
}
Run Code Online (Sandbox Code Playgroud)

当我编译它时,我收到以下警告:

bindings.rs:5:26: 5:35 warning: use of unstable item, #[warn(unstable)] on by default
bindings.rs:5         let mut reader = io::stdin();
                                       ^~~~~~~~~
bindings.rs:6:28: 6:39 warning: use of unstable item, #[warn(unstable)] on by default
bindings.rs:6         let input = reader.read_line().ok().expect("Failed to read line");
                                         ^~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)

有没有办法补救这些警告?

She*_*ter 14

对于1.0版本,Rust希望为语言的整个生命周期提供语言和标准库的哪些功能提供非常有力的保证.这不是一件容易的事!

新的,未经测试的或刚刚未完全烹饪的功能将标记为稳定属性,并且您将无法在测试版或发行版中使用不稳定的功能.您只能在夜间构建中使用它们.

然而,在alpha期间,它们只是警告.如果您需要使用alpha中的某个功能并将其标记为unstable,那么您需要确保它在测试版之前变得稳定(或者您找到了替代解决方案)!

在这种情况下,整个IO子系统正在进行最后一分钟的更改,因此它被标记为不稳定.

编辑1

当PR 21543降落时,当前的世界std::io将被重新命名为std::old_io.将编写新编写的代码std::io,旧版本将被弃用.

  • 我所知道的两个是[beta稳定代谢](https://github.com/rust-lang/rust/issues/20761)和[IO改革RFC](https://github.com/rust-)郎/ RFC文档/拉/ 517 /) (6认同)