Skip to content

Commit

Permalink
Remove function asyncness properly
Browse files Browse the repository at this point in the history
  • Loading branch information
kajacx committed Mar 9, 2024
1 parent ccc8f74 commit 56c05ce
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions crates/wasm-bridge-macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::str::FromStr;

use original::{Style, VariantStyle};
use quote::ToTokens;
use regex::{Captures, Regex};
use syn::Attribute;
use syn::{Attribute, ImplItem, ItemImpl};

mod original;

Expand Down Expand Up @@ -162,13 +163,13 @@ pub fn async_trait(
_attr: proc_macro::TokenStream,
input: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let as_string = input.to_string();

// FIXME: this will break user's "async fn" str slices for example, implement it properly!
let regex = Regex::new("async\\s*fn").unwrap();
let as_string = regex.replace_all(&as_string, "fn");

proc_macro::TokenStream::from_str(&as_string).unwrap()
let mut item_impl: ItemImpl = syn::parse(input).unwrap();
for item in item_impl.items.iter_mut() {
if let ImplItem::Fn(method) = item {
method.sig.asyncness = None;
}
}
item_impl.into_token_stream().into()
}

fn replace_namespace_str(stream: proc_macro::TokenStream) -> String {
Expand Down

0 comments on commit 56c05ce

Please sign in to comment.