One of the things I like about Rust is that it’s usually pretty to see where names come from - if I’m reading code and I want to know where something is declared, I can just search within the file, and I’ll either find the declaration or the import. The two large exceptions I’ve found to this are glob imports (fair enough), but also trait methods. For example:
use std::rand::Rng;
use std::rand::XorShiftRng;
fn main() {
let mut rng = XorShiftRng::new_unseeded();
println!("{}", rng.next_u32());
}
The import of Rng
gives no indication of where it’s used, and the use of next_u32
gives no indication that it comes from Rng
.
I think, like glob imports, it makes sense to allow this behavior and leave it up to the user to decide when and where it’s appropriate, but if what if you could use std::rand::Rng::next_u32;
?