-
Notifications
You must be signed in to change notification settings - Fork 89
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
Only generate ValidationError when needed #203
Conversation
Custom validation errors are converted to strings if the deriving struct doesn't specify a type for the errors returned by the `build` method. This variant was generated even when it wasn't needed, resulting in a reference to `String` that broke no_std. This change only emits that variant when `build_fn(validate = "...")` is set **and** `build_fn(error = "...")` is not set. This means no_std will work in the simple case with no additional meta items needed. Fixes #201
@andy128k please take a look |
rust-analyzer didn't touch trailing whitespace in a macro, which caused rustfmt to bail out.
This may break a compatibility with a code where custom validation is not provided but a field is annotated as |
The example now calls that out with the phantom_validate function. |
Another option is to not generate |
I have a preference for continuing to generate the variant in the case that a validation function is provided, as that avoids making the use of |
|
Today I learned. I’m still inclined to preserve the 0.10.0 decision of using String for the error type in the generated case and omitting it if we don’t need the variant. I don’t love that it’s “magical” but I really don’t want to break people using |
Version 0.9.0 emitted build method like |
Went with #204 instead |
Custom validation errors are converted to strings if the deriving struct doesn't specify a type for the errors returned by the
build
method. This variant was generated even when it wasn't needed, resulting in a reference toString
that broke no_std.This change only emits that variant when
build_fn(validate = "...")
is set andbuild_fn(error = "...")
is not set. This means no_std will work in the simple case with no additional meta items needed.Fixes #201