Rust 书中的 stdio 示例使用不稳定的库功能 'old_io' - 存在哪些替代方案?
stdio example in Rust book uses unstable library feature 'old_io' - what alternatives exist?
我有以下来自 Rust book 的 Rust 代码:
fn main() {
println!("Type something: ");
let input = std::old_io::stdin().read_line().ok().expect("Failed to read line!");
println!("Here's what you said: {}", input);
}
当我使用 rustc hello.rs
编译此示例时,我得到以下输出:
hello.rs:4:38: 4:49 error: use of unstable library feature 'old_io'
hello.rs:4 let input = std::old_io::stdin().read_line().ok().expect("Failed
to read line!");
^~~~~~~~~~~
hello.rs:4:49: 4:49 help: add #![feature(old_io)] to the crate attributes to ena
ble
hello.rs:4:17: 4:35 error: use of unstable library feature 'old_io'
hello.rs:4 let input = std::old_io::stdin().read_line().ok().expect("Failed
to read line!");
^~~~~~~~~~~~~~~~~~
hello.rs:4:35: 4:35 help: add #![feature(old_io)] to the crate attributes to ena
ble
hello.rs:4:38: 4:49 warning: use of deprecated item, #[warn(deprecated)] on by d
efault
hello.rs:4 let input = std::old_io::stdin().read_line().ok().expect("Failed
to read line!");
^~~~~~~~~~~
hello.rs:4:17: 4:35 warning: use of deprecated item, #[warn(deprecated)] on by d
efault
hello.rs:4 let input = std::old_io::stdin().read_line().ok().expect("Failed
to read line!");
^~~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors
文档作者似乎没有编译问题(或者如果 he/she 有,他们没有指出任何补救方法)。使用 std::io
会出现类似的错误。我在这里有什么选择?
这好像是bug 23760。作为解决方法,做
fn main() {
println!("Type something: ");
let mut s = String::new();
let count = std::io::stdin().read_line(&mut s).ok().expect("Failed to read line!");
println!("Here's what you said: {} ({} bytes)", s, count);
}
不幸的是,Steve points out:
These are the [examples] we can't run automated tests for :(
我有以下来自 Rust book 的 Rust 代码:
fn main() {
println!("Type something: ");
let input = std::old_io::stdin().read_line().ok().expect("Failed to read line!");
println!("Here's what you said: {}", input);
}
当我使用 rustc hello.rs
编译此示例时,我得到以下输出:
hello.rs:4:38: 4:49 error: use of unstable library feature 'old_io'
hello.rs:4 let input = std::old_io::stdin().read_line().ok().expect("Failed
to read line!");
^~~~~~~~~~~
hello.rs:4:49: 4:49 help: add #![feature(old_io)] to the crate attributes to ena
ble
hello.rs:4:17: 4:35 error: use of unstable library feature 'old_io'
hello.rs:4 let input = std::old_io::stdin().read_line().ok().expect("Failed
to read line!");
^~~~~~~~~~~~~~~~~~
hello.rs:4:35: 4:35 help: add #![feature(old_io)] to the crate attributes to ena
ble
hello.rs:4:38: 4:49 warning: use of deprecated item, #[warn(deprecated)] on by d
efault
hello.rs:4 let input = std::old_io::stdin().read_line().ok().expect("Failed
to read line!");
^~~~~~~~~~~
hello.rs:4:17: 4:35 warning: use of deprecated item, #[warn(deprecated)] on by d
efault
hello.rs:4 let input = std::old_io::stdin().read_line().ok().expect("Failed
to read line!");
^~~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors
文档作者似乎没有编译问题(或者如果 he/she 有,他们没有指出任何补救方法)。使用 std::io
会出现类似的错误。我在这里有什么选择?
这好像是bug 23760。作为解决方法,做
fn main() {
println!("Type something: ");
let mut s = String::new();
let count = std::io::stdin().read_line(&mut s).ok().expect("Failed to read line!");
println!("Here's what you said: {} ({} bytes)", s, count);
}
不幸的是,Steve points out:
These are the [examples] we can't run automated tests for :(