Skip to content

Implement length rule for urls #147

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

raffomania
Copy link

@raffomania raffomania commented Apr 14, 2025

I'm using Url structs directly in my forms to make working with them more convenient. With this patch, garde can validate the length of these structs.

Notes:

  • I copied and adapted most of the existing url tests to check the new length functionality; I'm not sure if it's really necessary to test the new stuff using enums, tuples etc.
  • I didn't try it, but it would be super cool to implement length rules for types that implement AsStr, e.g. impl HasSimpleLength for <T: AsStr>. Then we could just impl AsStr for Url and unlock more rules for Url structs. Even if it's not feasible for length rules, implementing AsStr for Url might be a good addition in a second PR.
  • I put the new rule implementations into the rules/url module rather than the individual rules/length modules, as I think it's worthwile to have all functionality gated behind the url feature in one place. If you think it's better the other way around I'll change it.

I'm happy to change the approach if you think it makes more sense in another way!

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.

1 participant