tracing icon indicating copy to clipboard operation
tracing copied to clipboard

Use macros for module declarations on fmt module

Open k-nasa opened this issue 4 years ago • 4 comments

Motivation

ref: https://github.com/tokio-rs/tracing/pull/1009

This is code refactoring. Currently, there is a lot of code that declares modules as follows:

#[cfg(feature = "registry")]
#[cfg_attr(docsrs, doc(cfg(feature = "registry")))]
pub use registry::Registry;

#[cfg(feature = "registry")]
#[cfg_attr(docsrs, doc(cfg(feature = "registry")))]
pub fn registry() -> Registry {
    Registry::default()
}

It is verbose to write a module declaration multiple times using the feature attribute. Also, if the definition for the same feature spans multiple places, it will be a little harder to read the code.

Solution

You can combine features attributes in one place by writing as follows. It also eliminates the need to write the same code over and over again.

cfg_feature!("feature" ,{
    pub use registry::Registry;

    pub fn registry() -> Registry {
        Registry::default()
    }
});

k-nasa avatar Oct 31 '20 08:10 k-nasa

Thanks! Can you format this PR to pass CI?

davidbarsky avatar Nov 02 '20 17:11 davidbarsky

Do you know why ci displays an error?

k-nasa avatar Nov 03 '20 06:11 k-nasa

Looks like some merge conflicts need to be resolved?

hawkw avatar Nov 21 '20 17:11 hawkw

We could probably still re-base and get this merged fyi @k-nasa

bryangarza avatar May 06 '22 00:05 bryangarza