Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@chilabot

Description

@chilabot

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions