Using stdlib in crate


#1

I am having difficulty understanding the use rule for std in crate.

Say I have a lib.rs sitting in src/. I want to use fully qualified std functions or traits, such as std::io::Read in my crate. I can only reference as ::std::io::Read, but not std::io::Read. I can’t use use ::std in the crate either, because the compiler complains it “conflicts with imported crate”.
I can use use ::std in the submodule though, so that std::io::Read works in this submodule after the use ::std added at the start of the module.

Can someone please explain how std is defaultly imported in the crate root?


#2

Because the compiler does it for you.

Hmm. This program works:

fn main() {
    let x: &std::io::Read;
}

So you should be able to without the ::.


#3

Ah, my bad. I was using std::io::Read in my inline tests module. No wonder!

Another question is, use super::* seems not implying use super::std;. Does asterisk exclude module?


#4

Ah ha! :slightly_smiling:

I am 99% sure that is true, but I don’t use globs very often. This ticket is related: