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

Make a struct iterable #4389

Closed
reenigneEsrever92 opened this issue Jan 1, 2025 · 1 comment
Closed

Make a struct iterable #4389

reenigneEsrever92 opened this issue Jan 1, 2025 · 1 comment
Labels

Comments

@reenigneEsrever92
Copy link

reenigneEsrever92 commented Jan 1, 2025

Summary

Is it possible to make a struct iterable?

Additional Details

I want to define a struct in rust:

#[wasm_bindgen]
unsafe extern "C" {
    pub unsafe fn print(pos: Pos);
}

#[wasm_bindgen]
struct Pos {
    x: f64,
    y: f64
}

fn main() {
    print(Pos { x: 1.0, y: 2.0 });
}

so that if I pass it to js it can be iterated (implement Symbols.iterator method):

function print(pos) {
    for (const key in pos) {
        console.log(`${key}: ${pos[key]}`);
    }
}

prints:

x: 1
y: 2
@daxpedda
Copy link
Collaborator

daxpedda commented Jan 7, 2025

This is not currently supported. See #1478 for workarounds. Also see #4142 for a proposal on how to address this.

Closing as duplicate of #1478.

@daxpedda daxpedda closed this as not planned Won't fix, can't repro, duplicate, stale Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants