nrc / derive-new

derive simple constructor functions for Rust structs
MIT License
525 stars 35 forks source link

[Feature] Support `impl Into<FieldTy>` for new parameters. #62

Closed xFrednet closed 2 months ago

xFrednet commented 1 year ago

I'm working on a project, that requires types to be transformed into an internal representation. Usually, this is done by calling .into() on the type. It would be awesome if the generated macro would support impl Into<FieldTy> parameters.

I imagine something like this:

#[derive(new)]
struct Foo {
    #[new(into)]
    x: u32,
}

which would generate:

impl Foo {
    fn new(x: impl Into<u32>) {
         Foo {
             x: x.into(),
         }
    }
}
OmarTawfik commented 10 months ago

I implemented the feature in #65 (first time contributor to this crate). Please let me know what you think.

polarathene commented 2 months ago

@nrc this issue can be closed since the #65 PR was merged?

xFrednet commented 2 months ago

Thank you for the implementation!