Skip to content

Commit

Permalink
Add ValidateRegex Implementation For Box, Rc, and Arc (#348)
Browse files Browse the repository at this point in the history
* Add ValidateRegex Implementation For Box, Rc, and Arc

* Remove unecessary import

* Remove unintended extra line

* Implement Validate Regex For Str
  • Loading branch information
Kailokk committed Aug 21, 2024
1 parent 0872516 commit 411bc9f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions validator/src/validation/regex.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::borrow::Cow;
use std::cell::OnceCell;
use std::rc::Rc;
use std::sync::{Arc, Mutex, OnceLock};

use regex::Regex;
Expand Down Expand Up @@ -100,3 +101,27 @@ impl ValidateRegex for &str {
regex.as_regex().is_match(self)
}
}

impl ValidateRegex for str {
fn validate_regex(&self, regex: impl AsRegex) -> bool {
regex.as_regex().is_match(self)
}
}

impl<T:ValidateRegex> ValidateRegex for Box<T> {
fn validate_regex(&self, regex: impl AsRegex) -> bool {
self.as_ref().validate_regex(regex)
}
}

impl<T:ValidateRegex> ValidateRegex for Rc<T> {
fn validate_regex(&self, regex: impl AsRegex) -> bool {
self.as_ref().validate_regex(regex)
}
}

impl<T:ValidateRegex> ValidateRegex for Arc<T> {
fn validate_regex(&self, regex: impl AsRegex) -> bool {
self.as_ref().validate_regex(regex)
}
}

0 comments on commit 411bc9f

Please sign in to comment.