Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
name: Continuous integration
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
- name: Extract Rust version from Cargo.toml
run: |
MSRV=$(sed -n 's/^rust-version = "\([^"]*\)"/\1/p' Cargo.toml)
Expand All @@ -16,6 +16,7 @@ jobs:
uses: dtolnay/rust-toolchain@stable # actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ env.MSRV }}
components: clippy,rustfmt
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
- name: Build System Info
Expand All @@ -26,6 +27,11 @@ jobs:
cargo test --no-default-features
cargo build --features derive --features card
cargo test --features derive --features card
- name: Format check
run: cargo fmt --check
- name: Run Clippy
run: cargo clippy --all-targets --features derive --features card -- -D warnings

test_validator-nightly:
name: Continuous integration
runs-on: ubuntu-latest
Expand All @@ -34,7 +40,7 @@ jobs:
include:
- rust: nightly
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
Expand All @@ -48,4 +54,4 @@ jobs:
cargo build --no-default-features
cargo test --no-default-features
cargo build --all-features
cargo test --all-features
cargo test --all-features
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ resolver = "2"
members = ["validator", "validator_derive", "validator_derive_tests"]

[workspace.package]
rust-version = "1.81"
rust-version = "1.86"
4 changes: 2 additions & 2 deletions validator/src/validation/cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ pub trait ValidateCreditCard {
CardValidate::from(&card_string).is_ok()
}

fn as_credit_card_string(&self) -> Cow<str>;
fn as_credit_card_string(&self) -> Cow<'_, str>;
}

impl<T: AsRef<str>> ValidateCreditCard for T {
fn as_credit_card_string(&self) -> Cow<str> {
fn as_credit_card_string(&self) -> Cow<'_, str> {
Cow::from(self.as_ref())
}
}
Expand Down
8 changes: 4 additions & 4 deletions validator/src/validation/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,20 @@ pub trait ValidateEmail {
true
}

fn as_email_string(&self) -> Option<Cow<str>>;
fn as_email_string(&self) -> Option<Cow<'_, str>>;
}

impl<T> ValidateEmail for &T
where
T: ValidateEmail,
{
fn as_email_string(&self) -> Option<Cow<str>> {
fn as_email_string(&self) -> Option<Cow<'_, str>> {
T::as_email_string(self)
}
}

impl ValidateEmail for String {
fn as_email_string(&self) -> Option<Cow<str>> {
fn as_email_string(&self) -> Option<Cow<'_, str>> {
Some(Cow::from(self))
}
}
Expand All @@ -99,7 +99,7 @@ impl<T> ValidateEmail for Option<T>
where
T: ValidateEmail,
{
fn as_email_string(&self) -> Option<Cow<str>> {
fn as_email_string(&self) -> Option<Cow<'_, str>> {
let Some(u) = self else {
return None;
};
Expand Down
18 changes: 9 additions & 9 deletions validator/src/validation/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use std::sync::{Arc, LazyLock, Mutex, OnceLock};
use regex::Regex;

pub trait AsRegex {
fn as_regex(&self) -> Cow<Regex>;
fn as_regex(&self) -> Cow<'_, Regex>;
}

impl AsRegex for Regex {
fn as_regex(&self) -> Cow<Regex> {
fn as_regex(&self) -> Cow<'_, Regex> {
Cow::Borrowed(self)
}
}
Expand All @@ -19,43 +19,43 @@ impl<T> AsRegex for &T
where
T: AsRegex,
{
fn as_regex(&self) -> Cow<Regex> {
fn as_regex(&self) -> Cow<'_, Regex> {
T::as_regex(self)
}
}

impl AsRegex for &OnceLock<Regex> {
fn as_regex(&self) -> Cow<Regex> {
fn as_regex(&self) -> Cow<'_, Regex> {
Cow::Borrowed(self.get().unwrap())
}
}

impl AsRegex for &Mutex<OnceCell<Regex>> {
fn as_regex(&self) -> Cow<Regex> {
fn as_regex(&self) -> Cow<'_, Regex> {
Cow::Owned(self.lock().unwrap().get().unwrap().clone())
}
}

impl AsRegex for &Mutex<OnceLock<Regex>> {
fn as_regex(&self) -> Cow<Regex> {
fn as_regex(&self) -> Cow<'_, Regex> {
Cow::Owned(self.lock().unwrap().get().unwrap().clone())
}
}

impl AsRegex for &Arc<Mutex<OnceCell<Regex>>> {
fn as_regex(&self) -> Cow<Regex> {
fn as_regex(&self) -> Cow<'_, Regex> {
Cow::Owned(self.lock().unwrap().get().unwrap().clone())
}
}

impl AsRegex for &Arc<Mutex<OnceLock<Regex>>> {
fn as_regex(&self) -> Cow<Regex> {
fn as_regex(&self) -> Cow<'_, Regex> {
Cow::Owned(self.lock().unwrap().get().unwrap().clone())
}
}

impl AsRegex for LazyLock<Regex> {
fn as_regex(&self) -> Cow<Regex> {
fn as_regex(&self) -> Cow<'_, Regex> {
Cow::Borrowed(self)
}
}
Expand Down
8 changes: 4 additions & 4 deletions validator/src/validation/urls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub trait ValidateUrl {
}
}

fn as_url_string(&self) -> Option<Cow<str>>;
fn as_url_string(&self) -> Option<Cow<'_, str>>;
}

macro_rules! validate_type_that_derefs {
Expand All @@ -25,7 +25,7 @@ macro_rules! validate_type_that_derefs {
where
T: ValidateUrl,
{
fn as_url_string(&self) -> Option<Cow<str>> {
fn as_url_string(&self) -> Option<Cow<'_, str>> {
T::as_url_string(self)
}
}
Expand All @@ -42,7 +42,7 @@ validate_type_that_derefs!(RefMut<'_, T>);
macro_rules! validate_type_of_str {
($type_:ty) => {
impl ValidateUrl for $type_ {
fn as_url_string(&self) -> Option<Cow<str>> {
fn as_url_string(&self) -> Option<Cow<'_, str>> {
Some(Cow::Borrowed(self))
}
}
Expand All @@ -57,7 +57,7 @@ impl<T> ValidateUrl for Option<T>
where
T: ValidateUrl,
{
fn as_url_string(&self) -> Option<Cow<str>> {
fn as_url_string(&self) -> Option<Cow<'_, str>> {
let Some(u) = self else {
return None;
};
Expand Down
3 changes: 1 addition & 2 deletions validator_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@ impl ValidationData {
}

if let Data::Struct(fields) = &self.data {
let original_fields: Vec<&Field> =
fields.fields.iter().map(|f| &f.original).collect();
let original_fields: Vec<&Field> = fields.fields.iter().map(|f| &f.original).collect();
for f in &fields.fields {
f.parsed.validate(&self.ident, &original_fields, &f.original);
}
Expand Down
11 changes: 5 additions & 6 deletions validator_derive/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,11 @@ impl ValidateField {
pub fn number_options(&self) -> u8 {
fn find_option(mut count: u8, ty: &syn::Type) -> u8 {
if let syn::Type::Path(p) = ty {
let idents_of_path =
p.path.segments.iter().fold(String::new(), |mut acc, v| {
acc.push_str(&v.ident.to_string());
acc.push('|');
acc
});
let idents_of_path = p.path.segments.iter().fold(String::new(), |mut acc, v| {
acc.push_str(&v.ident.to_string());
acc.push('|');
acc
});

if OPTIONS_TYPE.contains(&idents_of_path.as_str()) {
count += 1;
Expand Down
20 changes: 13 additions & 7 deletions validator_derive_tests/tests/compile-fail/wrong_crate_alias.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,42 @@ error[E0432]: unresolved import `validator_other`
--> tests/compile-fail/wrong_crate_alias.rs:9:24
|
9 | #[validate(crate = "validator_other")]
| ^^^^^^^^^^^^^^^^^ use of undeclared crate or module `validator_other`
| ^^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `validator_other`
|
= help: if you wanted to use a crate named `validator_other`, use `cargo add validator_other` to add it to your `Cargo.toml`

error[E0433]: failed to resolve: use of undeclared crate or module `validator_other`
error[E0433]: failed to resolve: use of unresolved module or unlinked crate `validator_other`
--> tests/compile-fail/wrong_crate_alias.rs:9:24
|
9 | #[validate(crate = "validator_other")]
| ^^^^^^^^^^^^^^^^^ use of undeclared crate or module `validator_other`
| ^^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `validator_other`
|
= help: if you wanted to use a crate named `validator_other`, use `cargo add validator_other` to add it to your `Cargo.toml`
help: consider importing one of these structs
|
4 + use crate::validator_renamed::ValidationErrors;
|
4 + use validator::ValidationErrors;
|

error[E0433]: failed to resolve: use of undeclared crate or module `validator_other`
error[E0433]: failed to resolve: use of unresolved module or unlinked crate `validator_other`
--> tests/compile-fail/wrong_crate_alias.rs:9:24
|
9 | #[validate(crate = "validator_other")]
| ^^^^^^^^^^^^^^^^^ use of undeclared crate or module `validator_other`
| ^^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `validator_other`
|
= help: if you wanted to use a crate named `validator_other`, use `cargo add validator_other` to add it to your `Cargo.toml`
help: consider importing one of these structs
|
4 + use crate::validator_renamed::ValidationError;
|
4 + use validator::ValidationError;
|

error[E0433]: failed to resolve: use of undeclared crate or module `validator_other`
error[E0433]: failed to resolve: use of unresolved module or unlinked crate `validator_other`
--> tests/compile-fail/wrong_crate_alias.rs:9:24
|
9 | #[validate(crate = "validator_other")]
| ^^^^^^^^^^^^^^^^^ use of undeclared crate or module `validator_other`
| ^^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `validator_other`
|
= help: if you wanted to use a crate named `validator_other`, use `cargo add validator_other` to add it to your `Cargo.toml`
2 changes: 1 addition & 1 deletion validator_derive_tests/tests/credit_card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn can_validate_custom_impl_for_credit_card() {
}

impl validator::ValidateCreditCard for CustomCreditCard {
fn as_credit_card_string(&self) -> Cow<str> {
fn as_credit_card_string(&self) -> Cow<'_, str> {
Cow::from(format!("{}{}{}", &self.bin, &self.ian, &self.check,))
}
}
Expand Down
8 changes: 4 additions & 4 deletions validator_derive_tests/tests/ip.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::Serialize;
use std::fmt;
use validator::Validate;

#[test]
fn can_validate_ipv4() {
#[derive(Validate)]
Expand Down Expand Up @@ -170,9 +170,9 @@ fn can_validate_custom_impl_for_ip() {
val: CustomIp,
}

impl ToString for CustomIp {
fn to_string(&self) -> String {
format!("{}.{}.{}.{}", self.a, self.b, self.c, self.d)
impl fmt::Display for CustomIp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}.{}.{}.{}", self.a, self.b, self.c, self.d)
}
}

Expand Down
2 changes: 1 addition & 1 deletion validator_derive_tests/tests/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const MIN_CONST: usize = 0;
// Loose floating point comparison using EPSILON error bound
macro_rules! assert_float {
($e1:expr, $e2:expr) => {
assert!(($e2 - $e1).abs() < std::f64::EPSILON);
assert!(($e2 - $e1).abs() < f64::EPSILON);
};
}

Expand Down
Loading