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

Add the capability of 'init-only' fields. #59

Open
chilabot opened this issue Mar 6, 2023 · 0 comments
Open

Add the capability of 'init-only' fields. #59

chilabot opened this issue Mar 6, 2023 · 0 comments

Comments

@chilabot
Copy link

chilabot commented Mar 6, 2023

I'd be nice to have 'init-only' fields, so you can use them in field initialization:

#[derive(new)]
struct Test
{
    #[new(init)] // <---
    active: bool,

    #[new(value = "Other::new(active)")]
    other: Other
}

Like https://docs.python.org/3/library/dataclasses.html#init-only-variables

I don't think I'd add too much complexity and I'd be really useful. The workaround for this is to declare the init-field after 'other' and to store it in the struct, which also forces a copy if the initialized class takes the parameter by value.

@chilabot chilabot changed the title Add the capability of 'only-init' variables. Add the capability of 'init-only' variables. Mar 6, 2023
@chilabot chilabot changed the title Add the capability of 'init-only' variables. Add the capability of 'init-only' fields. Mar 6, 2023
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

No branches or pull requests

1 participant