Skip to content

add initializer code blocks #69

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

add initializer code blocks #69

wants to merge 2 commits into from

Conversation

BennoLossin
Copy link
Member

  • add code blocks to [try_][pin_]init! macros

Allow writing `_: { /* any number of statements */ }` in initializers to
run arbitrary code during initialization. It also allows declaring
values that can be used later in the initializer:

    init!(MyStruct {
        _: {
            let val = if check_something() {
                42
            } else {
                0
            };
        },
        foo: Foo::new(val),
    })

Signed-off-by: Benno Lossin <lossin@kernel.org>
Signed-off-by: Benno Lossin <lossin@kernel.org>
@BennoLossin
Copy link
Member Author

@Darksonn in your proposal you said that only super let bindings would persist between different {} scopes in intializers. At the moment, this implements that behavior for normal let bindings. Any thoughts on that?

@BennoLossin BennoLossin changed the title Dev/underscore add initializer code blocks Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant