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

an attribute for skipping a struct field validation #182

Closed
coderedart opened this issue Jan 8, 2022 · 5 comments
Closed

an attribute for skipping a struct field validation #182

coderedart opened this issue Jan 8, 2022 · 5 comments

Comments

@coderedart
Copy link

I would like to skip a struct field which is just a [f32; 3] and there's no validation to be performed. I was wondering if it is possible to have a attribute like #[serde(skip)] which can skip validation for a particular struct field.

eg: #[validate(skip)]

@Keats
Copy link
Owner

Keats commented Jan 8, 2022

Validation is only done if you are setting an attribute on the field so there would be nothing to skip?

@coderedart
Copy link
Author

coderedart commented Jan 8, 2022

oh, but it gives me an error when i try to derive validation on a struct with [f32; 3] field.

use validator::Validate;

#[derive(Debug, Clone, Validate)]
pub struct Thing {
    pub pos: [f32; 3],
}

just checked with a fresh crate just in case. I get the following error with validator = {version = "*", features = ["derive"]} in cargo.toml.

➜  othing git:(master) ✗ cargo check
    Checking othing v0.1.0 (/home/user/programming/othing)
error: Type `[f32 ; 3]` of field `pos` not supported
 --> src/lib.rs:7:14
  |
7 |     pub pos: [f32; 3],
  |              ^^^^^^^^

error: could not compile `othing` due to previous error

@Keats
Copy link
Owner

Keats commented Jan 9, 2022

Ah I see the issue. It should just ignore fields it doesn't recognize instead of erroring if there are no validators set on them.

@IniterWorker
Copy link
Contributor

I'm having the same probleme here. Do you have a workaround or a solution? Maybe I can contribute.

error: Type `[u8 ; 11]` of field `reserved` not supported
  --> libcmd/src/lib.rs:88:19
   |
88 |     pub reserved: [u8; 11],
   |                   ^^^^^^^^

@Keats
Copy link
Owner

Keats commented Feb 17, 2022

No solutions yet, someone will need to go in the proc macro code, ctrl+F "not supported" and skip it instead of erroring if there are not validators set

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

No branches or pull requests

3 participants