bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.2k stars 3.57k forks source link

Extension traits are re-exported by name #13959

Open benfrankel opened 4 months ago

benfrankel commented 4 months ago

Extension traits can be re-exported without bringing their name into scope using underscore imports:

pub mod prelude {
    // This brings the trait AND its name into scope. This is how bevy currently does it.
    //pub use crate::commands::BuildChildrenTransformExt;

    // This brings the trait into scope.
    pub use crate::commands::BuildChildrenTransformExt as _;
}

Users can still pull in the name if needed:

use bevy_transform::prelude::*;
use bevy_transform::commands::BuildChildrenTransformExt;

Benefits:

BenjaminBrienen commented 4 days ago

This is really interesting, I hadn't considered using trait as _ to avoid name collisions. At a glance this also works in preludes. For a future PR, could be nice to do this for extension style traits (e.g., AppAssetExt etc.) so the preludes aren't so heavy with names.

_Originally posted by @bushrat011899 in https://github.com/bevyengine/bevy/pull/16163#discussion_r1821705357_

BenjaminBrienen commented 4 days ago

I agree that use Trait as _ should be the standard in our code. I say even for normal use, not just exports.