Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support cfg_attr #23

Open
helgoboss opened this issue May 15, 2020 · 1 comment
Open

Add support cfg_attr #23

helgoboss opened this issue May 15, 2020 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@helgoboss
Copy link

First: Extremely practical crate! Thanks!

I wanted to use Cargo features and cfg_attr in order to be able to activate/deactivate the compilation of metering or change which set of functions is going to be measured. However, I ran into the problem that cfg_attr complained about measure not being an attribute.

Example:

#[cfg_attr(feature = "measure-audio", measure)]
pub fn my_audio_function() {
    todo!()
}

Is there any way to fix it? E.g. to make measure an actual attribute?

@helgoboss
Copy link
Author

Current workaround which helps at least for being able to completly disable compilation with metered: Create a fake attribute macro called measure in a proc-macro crate, in this example named "my-macros":

/// No-op macro as work-around for https://github.com/magnet/metered-rs/issues/23.
#[doc(hidden)]
#[proc_macro_attribute]
pub fn measure(_: TokenStream, input: TokenStream) -> TokenStream {
    input
}

And use it when measuring is disabled:

#[cfg(feature = "measure-audio")]
use metered::{metered, ResponseTime};
#[cfg(not(feature = "measure-audio"))]
use my_macros::measure;

// ...

@magnet magnet added enhancement New feature or request help wanted Extra attention is needed labels May 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants