简体   繁体   English

更新“rustc”后,“use std::io”可以破坏我的代码吗?

[英]Can `use std::io` break my code after update of `rustc`?

I'm learning rust for fun after C++ class and I'm wondering, can use std::io break my code after update of rustc edition to newer? I'm learning rust for fun after C++ class and I'm wondering, can use std::io break my code after update of rustc edition to newer?

For example, in C++ using using namespace std is bad, because if new function gets added to std your multiple translation units code may break after compiler update because of function with name same as function written by you was added to namespace std . For example, in C++ using using namespace std is bad, because if new function gets added to std your multiple translation units code may break after compiler update because of function with name same as function written by you was added to namespace std .

However in all the official rust tutorials use std::io is used.然而,在所有官方 rust 教程中use std::io

Can use std::io break my code in rust?可以use std::io破坏我在 rust 中的代码吗?

Just use std::io;只需use std::io; on its own cannot break your code between versions.它本身不能破坏版本之间的代码。 That declaration only brings the io name into scope and that won't change.该声明仅将io名称带入 scope 并且不会改变。

If you had done use std::io::*;如果你已经use std::io::*; , that would bring everything from the io module into scope similar to use namespace std; ,这会将io模块中的所有内容带入 scope,类似于use namespace std; in C++ and thus could break your code in the future, but wildcard imports are discouraged in general for that reason.在 C++ 中,因此将来可能会破坏您的代码,但出于这个原因,通常不鼓励通配符导入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM