Add --enable-method-chaining for the Rust generator.#1586
Add --enable-method-chaining for the Rust generator.#1586QuantumSegfault wants to merge 1 commit intobytecodealliance:mainfrom
--enable-method-chaining for the Rust generator.#1586Conversation
|
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. |
|
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! |
Resolves #1559
Implements an option for Rust guest bindings generation to have methods with no return (
-> ()) instead pass-through-> &Selfto allow chaining.For consistency, this also applies to exports, so all exports normally expecting empty returns must now return
self.