-
Notifications
You must be signed in to change notification settings - Fork 157
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
Next version #249
Next version #249
Conversation
Things that need to be done:
Things that would be very nice:
|
Why is moving to traits better than just calling plain functions, if I may ask? |
It's more flexible, any type can implement them - they don't have to live in the validator crate. |
Is there anybody working on the derive macro rewrite? |
I don't think so - I was planning to work on it once I'm a bit further with Tera v2 but I would be happy if someone wants to tackle it! |
I can try it this week, I'll open a PR |
How would that work for the macro though? As in, would it be a Also, I'm planning to write a crate that does not only validation, but also mutation. For example - if a mutator called Would the next version of validator support mutation? If so, I can directly use this (would be happy to help writing it as well) instead of writing something separately. |
Not for the validators, for the data structures. You will be able to take whatever map/array/string type you want and implement the traits yourself rather than having them in the validator crate.
No, imo that's unrelated business. You could use a custom serde serializer/deserializer fn for that |
Got it. Thanks for considering it. I'll try writing something over this week and see if I can make a crate out of it. I'll report back with any learnings I would have in case it helps with your next version. |
Ok, maybe we do want to ship that PR now and do the other changes (eg error schema changes) in another version? No need to hold it out longer I think. Thoughts? |
I feel like this would be a good change in it's own right, if the change would linger waiting for additional, more complex changes, it might be best to just do separate versions for each of these significant changes. |
* implemented validation trait for length * converted identation to spaces * changed the trait to not require HasLen * added macro for generating impls * implemented ValidateLength for some types * using trait validation instead of the function * added cfg for indexmap import * changed trait to require length * Revert "changed trait to require length" This reverts commit a77bdc9. * moved validation logic inside ValidateLength trait * added trait validation for required * added email trait validation * fixed trait validation for email * added range trait validation * fixed range trait * added url trait validation --------- Co-authored-by: Tilen Pintarič <tilen.pintaric@aviko.si>
#246) * feat(range): add exclusive minimum and exclusive maximum for `range` validation * test(range): add tests for `exc_min` and `exc_max` range validation * docs: add docs for `exc_min` and `exc_max` for `range` validation * chore: rename `exc_min`, `exc_max` to `exclusive_min`, `exclusive_max` * chore(validation.rs): get rid of `collide` function
* Fully remove code for old phone validation The phone validation code was partially removed in 897811a (Remove phone feature and code, 2023-05-12), but parts were left in leading to tests not passing. * Update compile-fail expected compiler errors
This test was checking that the derive macro assertion about the type not being one of the known string types was working, but now since we allow implementations of the email validation for third-party types there is no way for us to perform this check in the derive macro. The same assertion is still used for the credit card and non-control character validators, but those will also soon be switched to be trait-based.
* Avoid unnecessary case-insensitive regexes The case-insensitive flag `(?i)` requires regex with the unicode-case feature enabled which significantly increases the binary size and makes regex slower. * Disable unnecessary/unused regex features regex crate with default features enabled is huge, it significantly increases the binary size and compile time. Cargo features are additive, so once some feature is enabled anywhere in the dependency graph, there's no way to disable it, i.e. one (transitive) dependency infects the whole dependency graph. Since `#[validate(regex = "...")]` takes a path to a static Regex instance, not regex as a string, users have to add the `regex` dependency to their Cargo.toml to use it. Therefore, this change shouldn't break backward compatibility.
* Rewrite derive macro implementation * Add better error handling * Add new types to validator macro * Add empty files in tokens module * Removed i32 tests for length * Fix email to pass tests * fix length validation trait to work with u64 only * Add credit card token generation to macro * Add url token generation to macro * Add ValidateIp trait * Add ip token generation to macro * Remove unneeded import * Export ValidateIp trait from main crate * Add tests for ValidateIp macro * Add non control character token generation to macro * Add test for range with enums * Add range token generation to macro * Add required token generation to macro * Fix ValidationErrors merge function * Move contains trait to contains.rs * Add ValidateContains trait and fix tests * Add ValidateContains and DoesNotContain traits to macro * Add must match token generation to macro * Add regex token generation * Add custom validation token generation to macro * Add custom validation with arguments to macro * Add custom validation with args with contexts * Add custom validation recommit * Fix custom validation to work without lifetimes * Change custom validation to use closures * Fix tests for custom validation * Change custom validation to implement FnOnce and add tests * Remove code used for experementing * Remove unneeded code * Remove unused imports * Add schema with arguments and fix tests * Impl ValidateLength trait for Option types * Fix impls for ValidateRange * Fix duplicate use statements * Fix tests and add Option impls for Contains * Implement ValidateUrl traits for specific types * Implement ValidateEmail traits for specific types * Fix some tests and warnings * Add regex trait for validation * Fix to pass tests in validator lib * Fix range validation trait to pass tests * Update and remove unneeded dependencies * Add ValidateNested trait * Fix custom and nested validation * Fix Regex validator to work with OnceCell and OnceLock * Fix derive macro to support all the arguments * Remove unneeded functions and fix tests * Remove validator_types crate and fix tests * Update CI workflow * Fix custom to be used in nested validations * Fix custom validation to use context * Add custom nested validation with args test * Fix validation to use Validation trait * Remove conflicting trait * Fixed tests and remove ValidateContext trait * Fix nested validation * Fix custom args test * Add `nest_all_fields` attribute * Add better error handling and start fixing UI tests * Pass almost all tests * Add skip_on_field_errors attribute to schema * Remove rust beta channel from workflow * Use proc_macro_error instead of darling diagnostics feature * Conditionally run UI tests * Fix ci.yml * Fix ci.yml * Remove UI test for wrong type on range * Change trait impls to be consistent * Run cargo clippy --fix * Replace if else with match * Remove cargo-expand leftovers * Replace underscore with `#[allow(unused)]` * Add support for multiple schema validations * Remove serde original field name test
* Reduce boilerplate code using generics and macros * Remove `HasLen` Plus a couple of clippy suggestions
LazyLock in std is not stable
#279) Co-authored-by: decryphe <noreply@github.com>
Ok it's live! Thanks everyone |
This contains the work needed to make the lib use validation based on traits.