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

Allow pattern, contains, prefix and suffix accept expression #56

Merged
merged 5 commits into from
Jul 29, 2023

Conversation

jirutka
Copy link
Contributor

@jirutka jirutka commented Jul 28, 2023

use once_cell::sync::Lazy;
use regex::Regex;

static LAZY_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"[a-zA-Z0-9][a-zA-Z0-9_]+").unwrap());
const STR: &str = "test";

#[derive(garde::Validate)]
struct Test {
    #[garde(pattern(LAZY_RE))]
    v: String,

    #[garde(pattern(create_regex()))]
    w: String,

    #[garde(contains(STR))]
    x: String,
}

fn create_regex() -> Regex {
    Regex::new(r"^abcd|efgh$").unwrap()
}

Copy link
Owner

@jprochazk jprochazk left a comment

Choose a reason for hiding this comment

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

Overall, this looks good! I hope the proc macro was not too hard to work on. 🙂

There were a few minor changes that I thought made sense, let me know what you think.

deny.toml Show resolved Hide resolved
garde/src/rules/pattern.rs Show resolved Hide resolved
garde/tests/rules/suffix.rs Show resolved Hide resolved
garde_derive/src/emit.rs Show resolved Hide resolved
@jirutka
Copy link
Contributor Author

jirutka commented Jul 29, 2023

I hope the proc macro was not too hard to work on. slightly_smiling_face

On the contrary, it is very well structured. :)

There were a few minor changes that I thought made sense, let me know what you think.

They are all good!

I’ve squashed fixups to clean up the git history.

@jprochazk
Copy link
Owner

Thank you!

@jprochazk jprochazk merged commit 4df4c30 into jprochazk:main Jul 29, 2023
@jirutka jirutka deleted the arg-expr branch July 29, 2023 22:15
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