From 095f985cbc8e50001556ed41c5a915b8cdb0452d Mon Sep 17 00:00:00 2001 From: Mikkel ALMONTE--RINGAUD Date: Sun, 29 Dec 2024 03:05:07 +0100 Subject: [PATCH] fix(wasm): named api method --- wasm/examples/export_method.rs | 16 ++++++++++++++++ wasm/src/lib.rs | 17 ++--------------- 2 files changed, 18 insertions(+), 15 deletions(-) create mode 100644 wasm/examples/export_method.rs diff --git a/wasm/examples/export_method.rs b/wasm/examples/export_method.rs new file mode 100644 index 0000000..3f26da3 --- /dev/null +++ b/wasm/examples/export_method.rs @@ -0,0 +1,16 @@ +#[wasm::api_method(retrieveCAS)] +pub fn retrieve_cas() { + // a `fetcher` variable is available + // if the target architecture is `wasm32` +} + +// the method will be still called `update` in the generated bindings +#[wasm::api_method] +pub fn update() { + // a `fetcher` variable is available + // if the target architecture is `wasm32` +} + +fn main() { + println!("Hello, world!"); +} diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index 21dcb34..401e029 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -15,21 +15,8 @@ impl Parse for ApiMethodArgs { return Ok(ApiMethodArgs { js_name: None }); } - let content; - syn::parenthesized!(content in input); - - if content.is_empty() { - return Ok(ApiMethodArgs { js_name: None }); - } - - let js_name = if let Ok(ident) = content.parse::() { - ident.to_string() - } - else { - return Err(content.error("Expected identifier")); - }; - - Ok(ApiMethodArgs { js_name: Some(js_name) }) + let ident = input.parse::()?; + Ok(ApiMethodArgs { js_name: Some(ident.to_string()) }) } }