Relax the rules around derive
It looks like that nutype has its own special derive() implementation and it can really get in the way sometimes. For example, I want to use the sqlx::Type derive, but I can't:
#[nutype(
validate(not_empty, len_char_max = 20),
derive(sqlx::Type), // #[nutype] does not know how to derive `sqlx` trait.
sqlx(transparent)
)]
pub struct Name(String);
There's also issues regarding conditional derives: https://github.com/greyblake/nutype/issues/188
Would it be possible to relax the rule and just let the user use derive directly on the type?
Hi, thanks for reporting the problem.
Nutype takes a full control over derive(..) to ensure that it's not possible to derive traits that possibly can mutate value avoiding the constraints. E.g. deriving DerefMut would make a problem.
I have plans to have in-house support for Diesel and SQLx.
Would it be possible to relax the rule and just let the user use derive directly on the type? Also I have plan to add a feature like
unsafe-derive, which would allow users to derive whatever they want.
Deriving sqlx::Type is possible now with unsafe_derive() in 0.6.2:
#[nutype(
validate(not_empty, len_char_max = 20),
derive_unsafe(sqlx::Type),
sqlx(transparent) // However, there is no way to pass this attribute yet
)]
pub struct Name(String);