Skip to content

Commit

Permalink
Cleanup macro (ava-labs#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardpringle authored Nov 2, 2023
1 parent f6588c5 commit f735d94
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions x/programs/rust/sdk_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ pub fn public(_: TokenStream, item: TokenStream) -> TokenStream {
});

// Collect all parameter names and types into separate vectors.
let param_names: Vec<_> = full_params.clone().map(|(name, _)| name).collect();
// Copy the iterator so we can use it again.
let param_names_cloned: Vec<_> = param_names.clone();
let param_types: Vec<_> = full_params.map(|(_, ty)| ty).collect();
let (param_names, param_types): (Vec<_>, Vec<_>) = full_params.unzip();

// Extract the original function's return type. This must be a WASM supported type.
let return_type = &input.sig.output;
Expand All @@ -72,9 +69,10 @@ pub fn public(_: TokenStream, item: TokenStream) -> TokenStream {
#[no_mangle]
pub extern "C" fn #new_name(#(#param_names: #param_types), *) #return_type {
// .into() uses the From() on each argument in the iterator to convert it to the type we want. 70% sure about this statement.
#name(#(#param_names_cloned.into()),*) // This means that every parameter type must implement From<i64>(except for the supported primitive types).
#name(#(#param_names.into()),*) // This means that every parameter type must implement From<i64>(except for the supported primitive types).
}
};

TokenStream::from(output)
}

Expand Down

0 comments on commit f735d94

Please sign in to comment.