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

Issue

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.

However in all the official rust tutorials use std::io is used.

Can use std::io break my code in rust?

Solution

Just 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.

If you had done use std::io::*;, that would bring everything from the io module into scope similar to use namespace std; in C++ and thus could break your code in the future, but wildcard imports are discouraged in general for that reason.

Answered By – kmdreko

Answer Checked By – Willingham (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.