Skip to content

Add --enable-method-chaining for the Rust generator.#1586

Open
QuantumSegfault wants to merge 1 commit intobytecodealliance:mainfrom
QuantumSegfault:gen-rust-method-chain
Open

Add --enable-method-chaining for the Rust generator.#1586
QuantumSegfault wants to merge 1 commit intobytecodealliance:mainfrom
QuantumSegfault:gen-rust-method-chain

Conversation

@QuantumSegfault
Copy link
Copy Markdown

Resolves #1559

Implements an option for Rust guest bindings generation to have methods with no return (-> ()) instead pass-through -> &Self to allow chaining.

For consistency, this also applies to exports, so all exports normally expecting empty returns must now return self.

@QuantumSegfault
Copy link
Copy Markdown
Author

@QuantumSegfault
Copy link
Copy Markdown
Author

Thinking about this more, this feels more like a hack/workaround than an actual solution.

It works, but it's invasive (makes ALL void returns chainable; even if there's no good reason).

It's also language dependent (each language needs to do something like this themselves).

WebAssembly/component-model#334 is basically what we are trying to solve. But conversation on that stagnated.

@BjornTheProgrammer
Copy link
Copy Markdown

It is a bit of a hack due to the fact that the wit doesn't have the semantics to return the self parameter easily from a resource, but despite that I think it should still be included.

I think it is fine if this is something only used in the rust generator as well, since builder patterns like this are much more idiomatic in rust than in other languages.

Even though the function makes all void functions return references to self, I don't really believe that this creates much tangible harm. Also since it is an optional binding feature, it makes it only opt in for projects that are willing to adopt it. Eventually when wit is extended to allow some more idiomatic way of doing this without such a hack, this could always be removed.

The quality of life improvements for allowing this to be toggled in a rust project is immense. Currently a huge annoyance for people with our plugin system is that they need to write out each modification to a resource on a new line.

These are just my thoughts, and I really appreciate your great work!

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

Successfully merging this pull request may close these issues.

Make resource function default return reference to self

2 participants