Keats / validator

Simple validation for Rust structs
MIT License
2.07k stars 151 forks source link

error: Unexpected literal type `path` #333

Open simanacci opened 5 months ago

simanacci commented 5 months ago

I'm getting this error after upgrading to 18.1. validator = { version = "0.18.1", features = [ "derive" ] }, lazy_static = 1.4.0, regex = 1.10.5

lazy_static! {
    pub static ref NO_WHITE_SPACE: Regex = Regex::new(r"^[^\s]+(\s+[^\s]+)*$").unwrap();
}
#[derive(Debug, Deserialize, Validate, Serialize)]
pub struct Login {
    #[validate(
        required,
        length(min = 1, message = "Enter your Username"),
        regex(path = *NO_WHITE_SPACE, message = "Spaces aren't allowed")
    )]
    pub username: Option<String>,
}
error: Unexpected literal type `path`
   --> /home/simanacci/.cargo/registry/src/index.crates.io-6f17d22bba15001f/validator_derive-0.18.1/src/lib.rs:228:22
    |
228 | #[darling(and_then = ValidationData::validate)]
    |                      ^^^^^^^^^^^^^^

   Compiling dummy v0.7.0
error[E0599]: no function or associated item named `from_derive_input` found for struct `ValidationData` in the current scope
   --> /home/simanacci/.cargo/registry/src/index.crates.io-6f17d22bba15001f/validator_derive-0.18.1/src/lib.rs:288:49
    |
229 | struct ValidationData {
    | --------------------- function or associated item `from_derive_input` not found for this struct
...
288 |     let validation_data = match ValidationData::from_derive_input(&input) {
    |                                                 ^^^^^^^^^^^^^^^^^ function or associated item not found in `ValidationData`
    |
    = help: items from traits can only be used if the trait is implemented and in scope
    = note: the following trait defines an item `from_derive_input`, perhaps you need to implement it:
            candidate #1: `FromDeriveInput`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `validator_derive` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
JustPretender commented 3 months ago

I'm experiencing the same issue. @simanacci Have you managed to fix it?

Keats commented 3 months ago

It's a bit odd, the sample from the issue works for me on master 🤔