Skip to content

Commit

Permalink
fix(#3297): Allow variant skip
Browse files Browse the repository at this point in the history
provides a way to avoid havind this error:
only C-Style enums allowed with #[wasm_bindgen]

```rust
\#[wasm_bindgen]
pub enum Operation {
    INCREMENT,

    #[cfg(not(target_arch = "wasm32"))]
    #[wasm_bindgen(skip)]
    CUSTOM(fn(i32) -> i32),
}
```
  • Loading branch information
erwanvivien committed Jun 25, 2023
1 parent 5158764 commit 4b23f15
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/macro-support/src/parser.rs
Expand Up @@ -1298,9 +1298,21 @@ impl<'a> MacroParse<(&'a mut TokenStream, BindgenAttrs)> for syn::ItemEnum {
_ => bail_span!(self, "only public enums are allowed with #[wasm_bindgen]"),
}

fn skip(attrs: &mut Vec<syn::Attribute>) -> bool {
let Ok(attrs) = BindgenAttrs::find(attrs) else {
return false;
};

let result = attrs.skip().is_some();
attrs.check_used();

result
}

let variants = self
.variants
.iter()
.filter(|v| !skip(&mut (v.attrs).clone()))
.enumerate()
.map(|(i, v)| {
match v.fields {
Expand Down

0 comments on commit 4b23f15

Please sign in to comment.