Public item, but excluded from glob import

Is it possible to hide something from glob import, but still allow it to be public?

I have a few traits in my crate, and I want users to have most of them available, but not all, since some traits implement "you'd better know what you're doing" kind of functionality that I don't want to expose by default.

mod foo {
    pub use Foo;
    pub(but no glob) use Bar;

use foo::*; // get Foo, but not Bar

use foo:Bar; // but that's OK

I see some libraries are using a module called prelude for use with use foo::prelude::*, but I don't want to do that, because use foo::* would import the prelude symbol, and that's going to conflict sooner or later.

Libraries that use prelude encourage users to use foo::prelude::*; and never use foo::*;.

Why don't you just put the dangerous stuff in a public submodule? Users can then use use foo::* for normal usage and add use foo::iner::* if they need the advanced stuff.

1 Like