Skip to content

Commit

Permalink
fix(wasm): named api method
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited committed Dec 29, 2024
1 parent cf8d900 commit 095f985
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
16 changes: 16 additions & 0 deletions wasm/examples/export_method.rs
Original file line number Diff line number Diff line change
@@ -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!");
}
17 changes: 2 additions & 15 deletions wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>() {
ident.to_string()
}
else {
return Err(content.error("Expected identifier"));
};

Ok(ApiMethodArgs { js_name: Some(js_name) })
let ident = input.parse::<Ident>()?;
Ok(ApiMethodArgs { js_name: Some(ident.to_string()) })
}
}

Expand Down

0 comments on commit 095f985

Please sign in to comment.