Keats/validator

an attribute for skipping a struct field validation

Closed this issue · 5 comments

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 commented

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

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 commented

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.

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 commented

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