Skip to content

Support exporting Rust functions as variadic JS functions #694

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

Closed
richard-uk1 opened this issue Aug 13, 2018 · 3 comments
Closed

Support exporting Rust functions as variadic JS functions #694

richard-uk1 opened this issue Aug 13, 2018 · 3 comments

Comments

@richard-uk1
Copy link
Contributor

richard-uk1 commented Aug 13, 2018

Support the following example

#[wasm_bindgen(apply_ending_slice_bikeshedded)]
pub fn add(first: u32, second: u32, rest: &[u32]) -> u32 {
    rest.iter().sum() + first + second
}

callable from javascript as

import { add } from './wasm';

console.log(add(1, 2, 3, 4, 5)); // prints 15

You could implement the transformation in javascript as

function add(first, second, ..rest) {
    return add_from_rust(first, second, rest);
}

This is a prerequisite for implementing #503 the reverse of #503.

@alexcrichton
Copy link
Contributor

Seems plausible to me! I think though that this is the opposite of #503, right? (this is about defining something in Rust whereas that's about importing something defined in JS)

@richard-uk1
Copy link
Contributor Author

Yeah I don't know why I said prerequisite :)

@alexcrichton alexcrichton changed the title Support converting slices in rust into obj.apply([args]) in javascript Support exporting Rust functions as variadic JS functions Nov 1, 2018
@joaofreires
Copy link
Contributor

@alexcrichton maybe we can close this issue as #2954 has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants