Exporting

To export semantics from Rust to a script, you would use the #[export] attribute macro.

This macro automatically introspects the underlying Rust item, making it available in the script environment.

Typically, you would export Rust crate functions, statics, constants, struct types, and their impl blocks, including the implemented operators.

Export Macro Anatomy

The macro should be applied to the Rust item.

For example, this application is allowed:

#[export]
impl Foo {
    pub fn bar(&self) {}
}

But the following export is forbidden because the implementation method itself is not a Rust item:

// Missing `#[export]` annotation on the impl block.
impl Foo {
    #[export]
    pub fn bar(&self) {}
}

The export attribute may appear multiple times inside the introspected item and on the same Rust construct to specify more export details.

#[export]
impl Foo {
    // Private methods are not exported by default.
    // By annotating this method with an additional `#[export]` attribute,
    // you enforce the method's export.
    #[export]
    fn bar(&self) {}
}