-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
I'm maintaining a library for which we want to expose both sync and async versions, but not necessarily at the same time. For both compilation speed and crate size, we'd prefer to allow users to enable one or both of these versions independently.
I don't think this feature exists yet. If it does, then simply adding relevant documentation would be great! If it doesn't yet exist, I imagine it to look like this:
#[async_generic(sync_cfg(feature = "sync"), async_cfg(feature = "async"))]
fn foo() {}Which expands to
#[cfg(feature = "sync")]
fn foo() {}
#[cfg(feature = "async")]
async fn foo_async() {}This implies the following rules:
- The
#[cfg()]attribute only appears if the relevantsync_cfgorasync_cfgattribute is in the macro invocation - Anything which is valid in a
#[cfg()]attribute can go into thesync_cfgorasync_cfgspace
This allows for conditional compilation based on things other than raw features. For example, you might have
#[async_generic(async_cfg(any(target_family = "wasm", feature = "docs")))]
fn bar() {}which expands to
fn bar() {}
#[cfg(any(target_family = "wasm", feature = "docs"))]
async fn bar_async() {}If this feature does not exist, would you be positively inclined toward a PR adding it?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels