From 9597aef05cf9e106b4d13e79ee34d649cc32cb9d Mon Sep 17 00:00:00 2001 From: G2-Games Date: Tue, 23 Apr 2024 11:33:11 -0500 Subject: [PATCH] Fixed not compiling on WASM --- .cargo/config.toml | 4 ++-- src/backend/wasm.rs | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 68c7980..4865338 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -3,5 +3,5 @@ rustflags = ["--cfg=web_sys_unstable_apis"] [build] #just comment in the "current" target -target = "x86_64-unknown-linux-gnu" -#target = "wasm32-unknown-unknown" +#target = "x86_64-unknown-linux-gnu" +target = "wasm32-unknown-unknown" diff --git a/src/backend/wasm.rs b/src/backend/wasm.rs index 9828353..d909876 100644 --- a/src/backend/wasm.rs +++ b/src/backend/wasm.rs @@ -10,24 +10,24 @@ use web_sys::{ // Crate stuff use crate::usb::{ - ControlIn, ControlOut, ControlType, Descriptor, Device, Interface, Recipient, UsbError, + ControlIn, ControlOut, ControlType, UsbDescriptor, UsbDevice, UsbInterface, Recipient, UsbError, }; #[wasm_bindgen] #[derive(Debug)] -pub struct UsbDescriptor { +pub struct Descriptor { device: WasmUsbDevice, } #[wasm_bindgen] #[derive(Debug)] -pub struct UsbDevice { +pub struct Device { device: WasmUsbDevice, } #[wasm_bindgen] #[derive(Debug)] -pub struct UsbInterface { +pub struct Interface { device: WasmUsbDevice, _number: u8, } @@ -61,7 +61,7 @@ impl DeviceFilter { } #[wasm_bindgen] -pub async fn get_device(device_filter: Vec) -> Result { +pub async fn get_device(device_filter: Vec) -> Result { let window = web_sys::window().unwrap(); let navigator = window.navigator(); @@ -102,7 +102,7 @@ pub async fn get_device(device_filter: Vec) -> Result) -> Result) -> Result Result { Ok(Self::Device { @@ -307,10 +307,10 @@ impl Descriptor for UsbDescriptor { } } -impl Device for UsbDevice { - type Interface = UsbInterface; +impl UsbDevice for Device { + type Interface = Interface; - async fn open_interface(&self, number: u8) -> Result { + async fn open_interface(&self, number: u8) -> Result { let dev_promise = JsFuture::from(Promise::resolve(&self.device.claim_interface(number))).await; @@ -324,7 +324,7 @@ impl Device for UsbDevice { } }; - Ok(UsbInterface { + Ok(Interface { device: self.device.clone(), _number: number, }) @@ -381,7 +381,7 @@ impl Device for UsbDevice { } } -impl<'a> Interface<'a> for UsbInterface { +impl<'a> UsbInterface<'a> for Interface { async fn control_in(&self, data: crate::usb::ControlIn) -> Result, UsbError> { let length = data.length; let params: UsbControlTransferParameters = data.into();