Problem using derive Validate
Roms1383 opened this issue · comments
Hello !
I'm actually facing an issue while trying to use actix-web-validator
.
I probably have overlooked a simple thing, but to be honest I'm still very new to Rust.
issue
When using Validate
, e.g. :
// src/models.rs
use serde::Deserialize;
use actix_web_validator::Validate;
#[derive(Debug, Deserialize, Clone, Validate)]
pub struct MyStruct {
#[validate(length(min = 3, max = 60))]
pub name: String,
// ...
}
I get the following error 😕 :
pub trait Validate
The trait that validator_derive implements
failed to resolve: could not find `validator` in `{{root}}`
I naively tried to add the following in the root already ⚗️ :
// src/lib.rs
#[macro_use]
extern crate actix_web_validator;
// ...
Unsuccessfully 😅
context
- rustc 1.49.0 (e1884a8e3 2020-12-29)
- platform : MacOS BigSur 11.1
- actix-web-validator 2.0.3
- actix-web : 3
Thanks in advance for the help you can provide 😃
Ok for beginners like me reading this, I'm not sure it's the correct way to fix but anyway I got it working by adding crates dependencies to the Cargo.toml :
[dependencies]
# ...
validator = "0.12.0"
validator_derive = "0.12.0"
Or simply :
[dependencies]
# ...
validator = { version = "0.12", features = ["derive"] }
i get same problem.
As I see reexport Validate is a bad idea.
https://github.com/Keats/validator/blob/e39ec89f4026e97e3089dabc40e33129a1053a6b/validator_derive/src/lib.rs#L75
Validate
macro directly use ::validator
crate and reexporting can not help in this situation.
The correct way is to add explicit validator
dependency into your project as @Roms1383 proposes.
I will remove reexporting Validator in the next major release