Is there a way to use the cfg(feature) check on multiple statements?

前端 未结 2 922
刺人心
刺人心 2020-12-06 05:13

Is there a way to minimize the following feature check?

#[cfg(feature = \"eugene\")]
pub mod eugene_set_steam_id;
#[cfg(feature = \"eugene\")]
pub mod eugene         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-06 05:50

    You could create a private module that import all the files, and then let the parent module re-export everything from that private module:

    #[cfg(feature = "eugene")]
    #[path = ""]
    mod reexport_eugene_modules {
        pub mod eugene_set_steam_id;
        pub mod eugene_balance;
        pub mod eugene_force_map;
        pub mod eugene_rating;
        pub mod eugene_stat;
        pub mod eugene_steam_id;
        pub mod eugene_top;
    }
    
    #[cfg(feature = "eugene")]
    pub use reexport_eugene_modules::*;
    

    You still need to write that #[cfg] line twice though.

提交回复
热议问题