Exclude operator/keyword in modules?

Basically, I haven't found a simple way to exclude exported elements of a module, in some cases (maybe edge cases) I want to export everything in a prelude EXCEPT! For a specific struct or trait, that forces me to export manually everything:

pub use axum::extract::{
    ConnectInfo,
    DefaultBodyLimit,
    Extension,
    Form,
    FromRef,
    FromRequest,
    FromRequestParts,
    // Json, I want to exclude this structure, so manually I export everything and I comment this line ✨
    MatchedPath,
    NestedPath,
    OptionalFromRequest,
    OptionalFromRequestParts,
    OriginalUri,
    Path,
    Query,
    RawForm,
    RawPathParams,
    RawQuery,
    Request,
    State,
};

And maybe we can provide a slightly more ergonomic way to do the same, something like this:

pub use axum::extract::*;
priv use axum::extract::Json;

That must export everything in axum::extract excluding axum::extract::Json and we are providing a functionality to the reserved keyword priv

It's just an idea, but I want to hear some comments about this.

rather than using priv which only kinda makes sense in the context of re-exporting items, I think a better solution is to use ! (like gitignore) or ^ (like regexes):

use the_crate::prelude::{*, !bad_name};

that way the semantics have nothing to do with the visibility of the import, so you can use pub/pub(crate)/nothing and the rest of it works the same regardless.

1 Like

This actually works already: if you do

pub use axum::extract::*;
use axum::extract::Json;

then the private non-glob import hides the public glob import, and so you cannot import Json from the module that does this. Of course, one might want a way to get this effect without importing Json at all, or get it in a more explicit way.

14 Likes

cf. hidden_glob_reexports

I think an earlier thread about something like this was Hiding in Use & Re-Export