Skip to content

Why are derives inside of the nutype macro? #180

Answered by greyblake
zexa asked this question in Q&A
Discussion options

You must be logged in to vote

@zexa Hi, thanks for asking, the question is very valid!

In version 0.1.0 in fact deriving was like you suggested: https://github.com/greyblake/nutype/tree/v0.1.1?tab=readme-ov-file#a-few-more-examples (yeap, it even supported *).

Nutype overtakes full control over the traits than can be derived. To keep it simple, there is just a whitelist of traits that are allowed to be derived. The reason for this is to prevent deriving a traits that can mutate the inner state and violate the constraint by bypassing the validation (e.g. DerefMut would do that).

There are 2 reasons, why I've decided to move derive() within nutype macro.

  1. To make it explicit that the derive is fully controled by the nu…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by zexa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants