File tree 3 files changed +40
-6
lines changed
3 files changed +40
-6
lines changed Original file line number Diff line number Diff line change @@ -158,15 +158,17 @@ impl<T: Hash> fmt::Display for ShortHash<T> {
158
158
}
159
159
160
160
161
- /// Create a syn attribute for `#[cfg(web_sys_unstable_apis)]`.
162
- pub fn unstable_api_attr ( ) -> syn:: Attribute {
163
- syn:: parse_quote!( #[ cfg( web_sys_unstable_apis) ] )
161
+ /// Create syn attribute for `#[cfg(web_sys_unstable_apis)]` and a doc comment.
162
+ pub fn unstable_api_attrs ( ) -> proc_macro2:: TokenStream {
163
+ quote:: quote!(
164
+ #[ cfg( web_sys_unstable_apis) ]
165
+ #[ doc = "\n \n *This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as [described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*" ]
166
+ )
164
167
}
165
168
166
-
167
- pub fn maybe_unstable_api_attr ( unstable_api : bool ) -> Option < syn:: Attribute > {
169
+ pub fn maybe_unstable_api_attr ( unstable_api : bool ) -> Option < proc_macro2:: TokenStream > {
168
170
if unstable_api {
169
- Some ( unstable_api_attr ( ) )
171
+ Some ( unstable_api_attrs ( ) )
170
172
} else {
171
173
None
172
174
}
Original file line number Diff line number Diff line change 88
88
- [ Function Overloads] ( ./web-sys/function-overloads.md )
89
89
- [ Type Translations] ( ./web-sys/type-translations.md )
90
90
- [ Inheritance] ( ./web-sys/inheritance.md )
91
+ - [ Unstable APIs] ( ./web-sys/unstable-apis.md )
91
92
92
93
- [ Testing with ` wasm-bindgen-test ` ] ( ./wasm-bindgen-test/index.md )
93
94
- [ Usage] ( ./wasm-bindgen-test/usage.md )
Original file line number Diff line number Diff line change
1
+ # Unstable APIs
2
+
3
+ It's common for browsers to implement parts of a web API while the specification
4
+ for that API is still being written. The API may require frequent changes as the
5
+ specification continues to be developed, so the WebIDL is relatively unstable.
6
+
7
+ This causes some challenges for ` web-sys ` because it means ` web-sys ` would have
8
+ to make breaking API changes whenever the WebIDL changes. It also means that
9
+ previously published ` web-sys ` versions would be invalid, because the browser
10
+ API may have been changed to match the updated WebIDL.
11
+
12
+ To avoid frequent breaking changes for unstable APIs, ` web-sys ` hides all
13
+ unstable APIs through an attribute that looks like:
14
+
15
+ ``` rust
16
+ #[cfg(web_sys_unstable_apis)]
17
+ pub struct Foo ;
18
+ ```
19
+
20
+ By hiding unstable APIs through an attribute, it's necessary for crates to
21
+ explicitly opt-in to these reduced stability guarantees in order to use these
22
+ APIs. Specifically, these APIs do not follow semver and may break whenever the
23
+ WebIDL changes.
24
+
25
+ Crates can opt-in to unstable APIs at compile-time by passing the ` cfg ` flag
26
+ ` web_sys_unstable_apis ` . Typically the ` RUSTFLAGS ` environment variable is used
27
+ to do this. For example:
28
+
29
+ ``` bash
30
+ RUSTFLAGS=--cfg=web_sys_unstable_apis cargo run
31
+ ```
You can’t perform that action at this time.
0 commit comments