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 wasm_bindgen(skip) attribute #1410

Merged
merged 3 commits into from
Apr 15, 2019
Merged

Add wasm_bindgen(skip) attribute #1410

merged 3 commits into from
Apr 15, 2019

Conversation

alexlapa
Copy link
Contributor

@alexlapa alexlapa commented Mar 30, 2019

Resolves #1284.
Previous PR #1316 (closed).

Adds wasm_bindgen(skip) attribute to disable public fields exposure to JS.

Renamed attribute from 'ignore' to 'skip' according to @LegNeato's consideration to align naming with serde's #[serde(skip)].

@alexcrichton
Copy link
Contributor

Awesome, thanks for this!

Could you also add some documentation to the reference in guide/src/reference?

@alexlapa
Copy link
Contributor Author

@alexcrichton ,

Could you also add some documentation to the reference in guide/src/reference?

Done.

@alexcrichton alexcrichton merged commit 7ee4906 into rustwasm:master Apr 15, 2019
@alexcrichton
Copy link
Contributor

Thanks!

@Sayan751
Copy link

Sayan751 commented Sep 5, 2020

It seems that this attribute only works for struct fields. I think it also makes sense to enable application of this attribute for methods. I would expect when this attribute is applied to a method, it is ignored by wasm-bindgen. For example, it will let me write something like this:

impl MyStruct {

  #[wasm_bindgen(skip)]
  pub fn my_method() -> &str {
    //...
  }

}

The advantage being is that then I can keep all the methods, both exposed to WASM as well as to other Rust libs, inside a single impl block. This in turn generates nicer docs, by putting all methods inside a single impl block, w/o any superfluous section.

What you guys think?

@alexcrichton
Copy link
Contributor

Seems reasonable to me!

@emccorson
Copy link

emccorson commented Apr 21, 2023

It seems that this attribute only works for struct fields. I think it also makes sense to enable application of this attribute for methods

@Sayan751 Do you know if this was ever implemented? I was surprised to find skip doesn't work on methods and I came across this old issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add #[wasm_bindgen(ignore)] to ignore a pub field and not generate getters/setters for it
4 participants