Skip to content

Make resource function default return reference to self #1559

@BjornTheProgrammer

Description

@BjornTheProgrammer

In the rust guest implementaiton, it would be interesting to explore the idea of having the function return a reference to self if there isn't a return value. This would enable chaining like the following.

interface text {
    resource text-component {
        text: static func(plain: string) -> text-component;
        add-text: func(text: string);
        underlined: func(value: bool);
    }
}
fn main() {
    let text = TextComponent::text("My Component").underlined(true).add_text(" - my additional text here");
}

This could also be put under a feature flag in wit-bindgen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    gen-rustRelated to bindings for Rust-compiled-to-WebAssembly

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions