js_name = Blah
The js_name
attribute can be used to export a different name in JS than what
something is named in Rust. It can be applied to both exported Rust functions
and types.
For example, this is often used to convert between Rust's snake-cased identifiers into JavaScript's camel-cased identifiers:
This can be used in JavaScript as:
import { doTheThing } from './my_module';
const x = doTheThing();
console.log(x);
Like imports, js_name
can also be used to rename types exported to JS:
to be accessed like:
import { Foo } from './my_module';
// ...
Note that attaching methods to the JS class Foo
should be done via the
js_class
attribute:
It can also be used to rename parameters of exported functions and methods:
Which will generate the following JS bindings:
/**
* @param {string} firstArg
*/
export function foo(firstArg) {
// ...
}
export class Foo {
/**
* @param {number} firstArg
*/
foo(firstArg) {
// ...
}
}