Skip to content
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

Add must_not_match validator #365

Closed
wants to merge 4 commits into from

Conversation

Jawell
Copy link

@Jawell Jawell commented Jan 21, 2025

Hi there! I want to add one more validator if you don't mind

@Jawell
Copy link
Author

Jawell commented Jan 23, 2025

@Keats ping :)

@@ -178,6 +179,19 @@ impl ToTokens for ValidateField {
quote!()
};

// Must not match validation
let must_not_match = if let Some(must_not_match) = self.must_not_match.clone() {
// TODO: handle option for other
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that still a TODO?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understood correctly - it was handled

/// Validates that the 2 given fields do not match.
/// Both fields are optionals
#[must_use]
pub fn validate_must_not_match<T: Eq>(a: T, b: T) -> bool {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want Eq or PartialEq?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, should be PartialEq

@Jawell Jawell force-pushed the add-must-not-match-validator branch from 1dc4cb8 to 4d3607a Compare February 5, 2025 09:10
@Keats
Copy link
Owner

Keats commented Feb 9, 2025

Looks like legit failures

@Jawell
Copy link
Author

Jawell commented Feb 9, 2025

Looks like legit failures

I fixed tests

@Jawell
Copy link
Author

Jawell commented Feb 15, 2025

@Keats reminder :)

1 similar comment
@Jawell
Copy link
Author

Jawell commented Feb 22, 2025

@Keats reminder :)

@@ -212,8 +212,10 @@ const MIN_CONSTANT: i32 = 0;

```

### must_match
Tests whether the 2 fields are equal. `must_match` takes 1 string argument. It will error if the field
### must_match and must_not_match
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we can use must_match rather than create a new validator. Something like must_match(expected=false) with a default of true (bad name but just to illustrate)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you didn't approve generic not() (Add not_match validator #141) and we have contains and does_not_contain I thought that we need a new one

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, can we move on?

@Keats
Copy link
Owner

Keats commented Mar 7, 2025

After thinking about it in practice it would be easier to write a custom validator and doesn't make sense to be a default validator. I probably wouldn't even include must_match now if it wasn't already there tbh
Sorry about that

@Keats Keats closed this Mar 7, 2025
@Jawell
Copy link
Author

Jawell commented Mar 7, 2025

@Keats no problem
But only one question: how to access other fields in custom validators? I didn't find anything. I don't want to use use_context to pass something in .validate_with_args

@Keats
Copy link
Owner

Keats commented Mar 10, 2025

You can't right now, you have to do a schema level validation fn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants