Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[x/programs] Cleanup macro #598

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading