rust - Is there a way to use the cfg(feature) check on multiple statements? -
is there way minimize following feature check?
#[cfg(feature = "eugene")] pub mod eugene_set_steam_id; #[cfg(feature = "eugene")] pub mod eugene_balance; #[cfg(feature = "eugene")] pub mod eugene_force_map; #[cfg(feature = "eugene")] pub mod eugene_rating; #[cfg(feature = "eugene")] pub mod eugene_stat; #[cfg(feature = "eugene")] pub mod eugene_steam_id; #[cfg(feature = "eugene")] pub mod eugene_top;
to like:
#[cfg(feature = "eugene")] { 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; }
this better convey meaning , more ergonomic.
the cfg-if crate provides cfg-if!
macro should want:
#[macro_use] extern crate cfg_if; cfg_if! { if #[cfg(feature = "eugene")] { 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; } else { } }
in fact, describes using words:
a macro ergonomically define item depending on large number of
#[cfg]
parameters. structured if-else chain, first matching branch item gets emitted.
Comments
Post a Comment