derive-new icon indicating copy to clipboard operation
derive-new copied to clipboard

enable validation

Open evbo opened this issue 11 months ago • 0 comments

Could a NewOption be added to configure a custom validation function to run after the struct is instantiated?

This would allow us to then run https://docs.rs/crate/validator/0.20.0 inside of new

A common pattern is to enforce private access to struct fields so that new enforces non-empty string fields or collections.

Although it's possible to make new private and then write your own new_valid that calls new, the problem is you then have to add all of the arguments yourself to new_valid, which sort of is the intent of using derive-new to begin with.

evbo avatar Feb 13 '25 16:02 evbo