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

rust: trivial changes to wit definition alters the API of the generated code in an incompatible way #775

Open
yamt opened this issue Nov 30, 2023 · 2 comments
Labels
gen-rust Related to bindings for Rust-compiled-to-WebAssembly

Comments

@yamt
Copy link
Contributor

yamt commented Nov 30, 2023

for example,

package foo:bar;

interface hoge {
    variant v1 {
        a(u32),
    }
    set1: func(v: v1);
    get1: func() -> v1;

    variant v2 {
        a(u32),
        b(string),
    }
    set2: func(v: v2);
    get2: func() -> v2;
}

world useless {
    import hoge;
}

given the above wit definition, wit-bindgen rust a.wit generates functions like:

pub fn set1(v: V1,){
pub fn set2(v: &V2,){

it's a bit surprising to me they are incompatible.
IMO, it's better to keep the same API for trivial changes like this.
i suspect it's simpler for users to use the generated code if you always use borrowed parameters for compound types like variant/record/etc for example.

@alexcrichton alexcrichton added the gen-rust Related to bindings for Rust-compiled-to-WebAssembly label Nov 30, 2023
@pchickey
Copy link
Contributor

pchickey commented Nov 30, 2023

The change might be small in text, but semantically it is not trivial: the b(string) variant is of variable length, where as the a(u32) is of fixed length. This distinction is very meaningful in terms of how the bindings generator, as well as the user of the bindings, has to manage memory.

@yamt
Copy link
Contributor Author

yamt commented Dec 5, 2023

The change might be small in text, but semantically it is not trivial: the b(string) variant is of variable length, where as the a(u32) is of fixed length. This distinction is very meaningful in terms of how the bindings generator, as well as the user of the bindings, has to manage memory.

are you talking about something rust-specific?
the corresponding C binding doesn't seem to involve the incompatibility.

always use borrowed parameters for compound types like variant/record/etc

doesn't this work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gen-rust Related to bindings for Rust-compiled-to-WebAssembly
Projects
None yet
Development

No branches or pull requests

3 participants