Skip to content

Commit b87a901

Browse files
authored
added WebUSB API (#2345)
1 parent 1d2d345 commit b87a901

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2463
-13
lines changed

crates/web-sys/Cargo.toml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ AesKeyGenParams = []
4242
Algorithm = []
4343
AlignSetting = []
4444
AllowedBluetoothDevice = []
45+
AllowedUsbDevice = []
4546
AnalyserNode = ["AudioNode", "EventTarget"]
4647
AnalyserOptions = []
4748
AngleInstancedArrays = []
@@ -247,7 +248,6 @@ CustomEventInit = []
247248
DataTransfer = []
248249
DataTransferItem = []
249250
DataTransferItemList = []
250-
DataView = []
251251
DateTimeValue = []
252252
DecoderDoctorNotification = []
253253
DecoderDoctorNotificationType = []
@@ -1238,6 +1238,31 @@ UiEvent = ["Event"]
12381238
UiEventInit = []
12391239
Url = []
12401240
UrlSearchParams = []
1241+
Usb = ["EventTarget"]
1242+
UsbAlternateInterface = []
1243+
UsbConfiguration = []
1244+
UsbConnectionEvent = ["Event"]
1245+
UsbConnectionEventInit = []
1246+
UsbControlTransferParameters = []
1247+
UsbDevice = []
1248+
UsbDeviceFilter = []
1249+
UsbDeviceRequestOptions = []
1250+
UsbDirection = []
1251+
UsbEndpoint = []
1252+
UsbEndpointType = []
1253+
UsbInTransferResult = []
1254+
UsbInterface = []
1255+
UsbIsochronousInTransferPacket = []
1256+
UsbIsochronousInTransferResult = []
1257+
UsbIsochronousOutTransferPacket = []
1258+
UsbIsochronousOutTransferResult = []
1259+
UsbOutTransferResult = []
1260+
UsbPermissionDescriptor = []
1261+
UsbPermissionResult = ["EventTarget", "PermissionStatus"]
1262+
UsbPermissionStorage = []
1263+
UsbRecipient = []
1264+
UsbRequestType = []
1265+
UsbTransferStatus = []
12411266
UserProximityEvent = ["Event"]
12421267
UserProximityEventInit = []
12431268
UserVerificationRequirement = []
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#![allow(unused_imports)]
2+
use super::*;
3+
use wasm_bindgen::prelude::*;
4+
#[cfg(web_sys_unstable_apis)]
5+
#[wasm_bindgen]
6+
extern "C" {
7+
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = AllowedUSBDevice)]
8+
#[derive(Debug, Clone, PartialEq, Eq)]
9+
#[doc = "The `AllowedUsbDevice` dictionary."]
10+
#[doc = ""]
11+
#[doc = "*This API requires the following crate features to be activated: `AllowedUsbDevice`*"]
12+
#[doc = ""]
13+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
14+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
15+
pub type AllowedUsbDevice;
16+
}
17+
#[cfg(web_sys_unstable_apis)]
18+
impl AllowedUsbDevice {
19+
#[doc = "Construct a new `AllowedUsbDevice`."]
20+
#[doc = ""]
21+
#[doc = "*This API requires the following crate features to be activated: `AllowedUsbDevice`*"]
22+
#[doc = ""]
23+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
24+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
25+
pub fn new(product_id: u8, vendor_id: u8) -> Self {
26+
#[allow(unused_mut)]
27+
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
28+
ret.product_id(product_id);
29+
ret.vendor_id(vendor_id);
30+
ret
31+
}
32+
#[cfg(web_sys_unstable_apis)]
33+
#[doc = "Change the `productId` field of this object."]
34+
#[doc = ""]
35+
#[doc = "*This API requires the following crate features to be activated: `AllowedUsbDevice`*"]
36+
#[doc = ""]
37+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
38+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
39+
pub fn product_id(&mut self, val: u8) -> &mut Self {
40+
use wasm_bindgen::JsValue;
41+
let r = ::js_sys::Reflect::set(
42+
self.as_ref(),
43+
&JsValue::from("productId"),
44+
&JsValue::from(val),
45+
);
46+
debug_assert!(
47+
r.is_ok(),
48+
"setting properties should never fail on our dictionary objects"
49+
);
50+
let _ = r;
51+
self
52+
}
53+
#[cfg(web_sys_unstable_apis)]
54+
#[doc = "Change the `serialNumber` field of this object."]
55+
#[doc = ""]
56+
#[doc = "*This API requires the following crate features to be activated: `AllowedUsbDevice`*"]
57+
#[doc = ""]
58+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
59+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
60+
pub fn serial_number(&mut self, val: &str) -> &mut Self {
61+
use wasm_bindgen::JsValue;
62+
let r = ::js_sys::Reflect::set(
63+
self.as_ref(),
64+
&JsValue::from("serialNumber"),
65+
&JsValue::from(val),
66+
);
67+
debug_assert!(
68+
r.is_ok(),
69+
"setting properties should never fail on our dictionary objects"
70+
);
71+
let _ = r;
72+
self
73+
}
74+
#[cfg(web_sys_unstable_apis)]
75+
#[doc = "Change the `vendorId` field of this object."]
76+
#[doc = ""]
77+
#[doc = "*This API requires the following crate features to be activated: `AllowedUsbDevice`*"]
78+
#[doc = ""]
79+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
80+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
81+
pub fn vendor_id(&mut self, val: u8) -> &mut Self {
82+
use wasm_bindgen::JsValue;
83+
let r = ::js_sys::Reflect::set(
84+
self.as_ref(),
85+
&JsValue::from("vendorId"),
86+
&JsValue::from(val),
87+
);
88+
debug_assert!(
89+
r.is_ok(),
90+
"setting properties should never fail on our dictionary objects"
91+
);
92+
let _ = r;
93+
self
94+
}
95+
}

crates/web-sys/src/features/gen_BluetoothAdvertisingEvent.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ extern "C" {
2828
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
2929
pub fn device(this: &BluetoothAdvertisingEvent) -> BluetoothDevice;
3030
#[cfg(web_sys_unstable_apis)]
31+
# [wasm_bindgen (structural , method , getter , js_class = "BluetoothAdvertisingEvent" , js_name = uuids)]
32+
#[doc = "Getter for the `uuids` field of this object."]
33+
#[doc = ""]
34+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/BluetoothAdvertisingEvent/uuids)"]
35+
#[doc = ""]
36+
#[doc = "*This API requires the following crate features to be activated: `BluetoothAdvertisingEvent`*"]
37+
#[doc = ""]
38+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
39+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
40+
pub fn uuids(this: &BluetoothAdvertisingEvent) -> ::js_sys::Array;
41+
#[cfg(web_sys_unstable_apis)]
3142
# [wasm_bindgen (structural , method , getter , js_class = "BluetoothAdvertisingEvent" , js_name = name)]
3243
#[doc = "Getter for the `name` field of this object."]
3344
#[doc = ""]

crates/web-sys/src/features/gen_BluetoothPermissionResult.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,26 @@ extern "C" {
1515
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
1616
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
1717
pub type BluetoothPermissionResult;
18+
#[cfg(web_sys_unstable_apis)]
19+
# [wasm_bindgen (structural , method , getter , js_class = "BluetoothPermissionResult" , js_name = devices)]
20+
#[doc = "Getter for the `devices` field of this object."]
21+
#[doc = ""]
22+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/BluetoothPermissionResult/devices)"]
23+
#[doc = ""]
24+
#[doc = "*This API requires the following crate features to be activated: `BluetoothPermissionResult`*"]
25+
#[doc = ""]
26+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
27+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
28+
pub fn devices(this: &BluetoothPermissionResult) -> ::js_sys::Array;
29+
#[cfg(web_sys_unstable_apis)]
30+
# [wasm_bindgen (structural , method , setter , js_class = "BluetoothPermissionResult" , js_name = devices)]
31+
#[doc = "Setter for the `devices` field of this object."]
32+
#[doc = ""]
33+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/BluetoothPermissionResult/devices)"]
34+
#[doc = ""]
35+
#[doc = "*This API requires the following crate features to be activated: `BluetoothPermissionResult`*"]
36+
#[doc = ""]
37+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
38+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
39+
pub fn set_devices(this: &BluetoothPermissionResult, value: &::wasm_bindgen::JsValue);
1840
}

crates/web-sys/src/features/gen_BluetoothRemoteGattCharacteristic.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,12 @@ extern "C" {
5353
this: &BluetoothRemoteGattCharacteristic,
5454
) -> BluetoothCharacteristicProperties;
5555
#[cfg(web_sys_unstable_apis)]
56-
#[cfg(feature = "DataView")]
5756
# [wasm_bindgen (structural , method , getter , js_class = "BluetoothRemoteGATTCharacteristic" , js_name = value)]
5857
#[doc = "Getter for the `value` field of this object."]
5958
#[doc = ""]
6059
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTCharacteristic/value)"]
6160
#[doc = ""]
62-
#[doc = "*This API requires the following crate features to be activated: `BluetoothRemoteGattCharacteristic`, `DataView`*"]
61+
#[doc = "*This API requires the following crate features to be activated: `BluetoothRemoteGattCharacteristic`*"]
6362
#[doc = ""]
6463
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
6564
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]

crates/web-sys/src/features/gen_BluetoothRemoteGattDescriptor.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,12 @@ extern "C" {
4141
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
4242
pub fn uuid(this: &BluetoothRemoteGattDescriptor) -> String;
4343
#[cfg(web_sys_unstable_apis)]
44-
#[cfg(feature = "DataView")]
4544
# [wasm_bindgen (structural , method , getter , js_class = "BluetoothRemoteGATTDescriptor" , js_name = value)]
4645
#[doc = "Getter for the `value` field of this object."]
4746
#[doc = ""]
4847
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTDescriptor/value)"]
4948
#[doc = ""]
50-
#[doc = "*This API requires the following crate features to be activated: `BluetoothRemoteGattDescriptor`, `DataView`*"]
49+
#[doc = "*This API requires the following crate features to be activated: `BluetoothRemoteGattDescriptor`*"]
5150
#[doc = ""]
5251
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
5352
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]

crates/web-sys/src/features/gen_ClipboardItem.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ extern "C" {
5050
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
5151
pub fn delayed(this: &ClipboardItem) -> bool;
5252
#[cfg(web_sys_unstable_apis)]
53+
# [wasm_bindgen (structural , method , getter , js_class = "ClipboardItem" , js_name = types)]
54+
#[doc = "Getter for the `types` field of this object."]
55+
#[doc = ""]
56+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem/types)"]
57+
#[doc = ""]
58+
#[doc = "*This API requires the following crate features to be activated: `ClipboardItem`*"]
59+
#[doc = ""]
60+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
61+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
62+
pub fn types(this: &ClipboardItem) -> ::js_sys::Array;
63+
#[cfg(web_sys_unstable_apis)]
5364
# [wasm_bindgen (method , structural , js_class = "ClipboardItem" , js_name = getType)]
5465
#[doc = "The `getType()` method."]
5566
#[doc = ""]

crates/web-sys/src/features/gen_GpuAdapter.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ extern "C" {
2727
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
2828
pub fn name(this: &GpuAdapter) -> String;
2929
#[cfg(web_sys_unstable_apis)]
30+
# [wasm_bindgen (structural , method , getter , js_class = "GPUAdapter" , js_name = extensions)]
31+
#[doc = "Getter for the `extensions` field of this object."]
32+
#[doc = ""]
33+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GPUAdapter/extensions)"]
34+
#[doc = ""]
35+
#[doc = "*This API requires the following crate features to be activated: `GpuAdapter`*"]
36+
#[doc = ""]
37+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
38+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
39+
pub fn extensions(this: &GpuAdapter) -> ::js_sys::Array;
40+
#[cfg(web_sys_unstable_apis)]
3041
# [wasm_bindgen (method , structural , js_class = "GPUAdapter" , js_name = requestDevice)]
3142
#[doc = "The `requestDevice()` method."]
3243
#[doc = ""]

crates/web-sys/src/features/gen_GpuCompilationInfo.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,15 @@ extern "C" {
1515
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
1616
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
1717
pub type GpuCompilationInfo;
18+
#[cfg(web_sys_unstable_apis)]
19+
# [wasm_bindgen (structural , method , getter , js_class = "GPUCompilationInfo" , js_name = messages)]
20+
#[doc = "Getter for the `messages` field of this object."]
21+
#[doc = ""]
22+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GPUCompilationInfo/messages)"]
23+
#[doc = ""]
24+
#[doc = "*This API requires the following crate features to be activated: `GpuCompilationInfo`*"]
25+
#[doc = ""]
26+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
27+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
28+
pub fn messages(this: &GpuCompilationInfo) -> ::js_sys::Array;
1829
}

crates/web-sys/src/features/gen_GpuDevice.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ extern "C" {
2828
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
2929
pub fn adapter(this: &GpuDevice) -> GpuAdapter;
3030
#[cfg(web_sys_unstable_apis)]
31+
# [wasm_bindgen (structural , method , getter , js_class = "GPUDevice" , js_name = extensions)]
32+
#[doc = "Getter for the `extensions` field of this object."]
33+
#[doc = ""]
34+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GPUDevice/extensions)"]
35+
#[doc = ""]
36+
#[doc = "*This API requires the following crate features to be activated: `GpuDevice`*"]
37+
#[doc = ""]
38+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
39+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
40+
pub fn extensions(this: &GpuDevice) -> ::js_sys::Array;
41+
#[cfg(web_sys_unstable_apis)]
3142
# [wasm_bindgen (structural , method , getter , js_class = "GPUDevice" , js_name = limits)]
3243
#[doc = "Getter for the `limits` field of this object."]
3344
#[doc = ""]

crates/web-sys/src/features/gen_Navigator.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ extern "C" {
141141
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
142142
pub fn gpu(this: &Navigator) -> Gpu;
143143
#[cfg(web_sys_unstable_apis)]
144+
#[cfg(feature = "Usb")]
145+
# [wasm_bindgen (structural , method , getter , js_class = "Navigator" , js_name = usb)]
146+
#[doc = "Getter for the `usb` field of this object."]
147+
#[doc = ""]
148+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/usb)"]
149+
#[doc = ""]
150+
#[doc = "*This API requires the following crate features to be activated: `Navigator`, `Usb`*"]
151+
#[doc = ""]
152+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
153+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
154+
pub fn usb(this: &Navigator) -> Usb;
155+
#[cfg(web_sys_unstable_apis)]
144156
#[cfg(feature = "Xr")]
145157
# [wasm_bindgen (structural , method , getter , js_class = "Navigator" , js_name = xr)]
146158
#[doc = "Getter for the `xr` field of this object."]

0 commit comments

Comments
 (0)