-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Description
I've been using Nutype for ages now with a lot of success. The fact that I can define value types that are guaranteed to be valid is a huge win for me.
However, I've just started using Garde for validation of other types in my system, and it would be nice to be able to use that for all validation. However, it turns out it doesn't work well with Nutype.
For example, this is what I started with:
#[nutype::nutype(sanitize(trim), validate(not_empty), derive(Clone, Debug, PartialEq, FromStr, AsRef))]
pub struct UserID(String);And that works fine.
If I try to swap to Garde I get either this:
#[nutype::nutype(sanitize(trim), derive(Clone, Debug, PartialEq, FromStr, AsRef, garde::Validate))]
pub struct UserID(#[garde(length(min = 1))] String);With this error:
error: #[nutype] does not know how to derive `garde` trait.
--> src/modules/users/domain/user/user_id.rs:1:82
|
1 | #[nutype::nutype(sanitize(trim), derive(Clone, Debug, PartialEq, FromStr, AsRef, garde::Validate))]
Or I get this:
#[derive(garde::Validate)]
#[nutype::nutype(sanitize(trim), derive(Clone, Debug, PartialEq, FromStr, AsRef))]
pub struct UserID(#[garde(length(min = 1))] String);With the error:
error[E0603]: tuple struct constructor `modules::users::domain::user::user_id::__nutype_UserID__::UserID` is private
--> src/modules/users/domain/user/user_id.rs:1:10
|
1 | #[derive(garde::Validate)]
| ^^^^^^^^^^^^^^^
|
= note: this error originates in the derive macro `garde::Validate` (in Nightly builds, run with -Z macro-backtrace for more info)
Or I get this:
#[nutype::nutype(sanitize(trim), derive(Clone, Debug, PartialEq, FromStr, AsRef))]
#[derive(garde::Validate)]
pub struct UserID(#[garde(length(min = 1))] String);With the error:
error: #[derive(..)] macro is not allowed to be used with #[nutype]. If you want to derive traits use `derive(..) attribute within #[nutype] macro:
#[nutype(
derive(Debug, Clone, AsRef)
)]
is there anything that can be done to use these two together?
Cheers
Metadata
Metadata
Assignees
Labels
No labels