Skip to content
This repository was archived by the owner on Apr 2, 2026. It is now read-only.

Commit 3451910

Browse files
authored
select!: allow #[cfg()] gates (#970)
This is handy to match some arguments only if a feature is enabled. For example: ``` select! { 'c' => (), #[cfg(feature = "uppercase-is-ok")] 'C' => () } ```
1 parent 6a38ac6 commit 3451910

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- `select!` and `select_ref!` now support cfg attributes.
13+
1214
### Removed
1315

1416
### Changed

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3173,10 +3173,10 @@ where
31733173
/// ```
31743174
#[macro_export]
31753175
macro_rules! select {
3176-
($($p:pat $(= $extra:ident)? $(if $guard:expr)? $(=> $out:expr)?),+ $(,)?) => ({
3176+
($($(#[$attr:meta])? $p:pat $(= $extra:ident)? $(if $guard:expr)? $(=> $out:expr)?),+ $(,)?) => ({
31773177
$crate::primitive::select(
31783178
move |x, extra| match (x, extra) {
3179-
$(($p $(,$extra)?, ..) $(if $guard)? => ::core::option::Option::Some({ () $(;$out)? })),+,
3179+
$($(#[$attr])? ($p $(,$extra)?, ..) $(if $guard)? => ::core::option::Option::Some({ () $(;$out)? })),+,
31803180
_ => ::core::option::Option::None,
31813181
}
31823182
)
@@ -3192,10 +3192,10 @@ macro_rules! select {
31923192
/// Requires that the parser input implements [`BorrowInput`].
31933193
#[macro_export]
31943194
macro_rules! select_ref {
3195-
($($p:pat $(= $extra:ident)? $(if $guard:expr)? $(=> $out:expr)?),+ $(,)?) => ({
3195+
($($(#[$attr:meta])? $p:pat $(= $extra:ident)? $(if $guard:expr)? $(=> $out:expr)?),+ $(,)?) => ({
31963196
$crate::primitive::select_ref(
31973197
move |x, extra| match (x, extra) {
3198-
$(($p $(,$extra)?, ..) $(if $guard)? => ::core::option::Option::Some({ () $(;$out)? })),+,
3198+
$($(#[$attr])? ($p $(,$extra)?, ..) $(if $guard)? => ::core::option::Option::Some({ () $(;$out)? })),+,
31993199
_ => ::core::option::Option::None,
32003200
}
32013201
)

0 commit comments

Comments
 (0)