Support for remote derive (or serde's from and into annotations) #3919
sunshowers
started this conversation in
Ideas
Replies: 1 comment
-
Thanks for filling this thread. I agree that this is an issue that deserves to be solved. Could you maybe try to provide an example of each suggested variant that shows:
(That just needs to be a really simple example, and it does only need to cover a single derive) I think that would make it much easier to understand what's actually suggested. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there, and thanks for maintaining Diesel! I have a suggestion for a feature request that should hopefully not be too onerous.
In one of our main repositories, we define some common types in a
common
crate. This crate does not depend on Diesel (and we'd like to keep it that way -- these types are used in many places that don't need database access).In our
db-model
crate, we would like to use these types directly inderive(Selectable)
etc. But, as I'm sure you know, that runs into orphan rule issues -- it's not possible to implement a foreign trait for a foreign type.The classic solution to that is to use a newtype. But now there are two very similar types floating around the system, and while there are ways to mitigate that it's still really annoying to manage.
While looking at ways to address this, I realized that serde may suggest a solution for this with its remote derive functionality. This could then be addressed with:
RemoteType
, and deriveAsExpression
etc on it.RemoteType
with#[diesel(remote = "BaseType")]
.Selectable
structs, use theBaseType``, and annotate it with
#[serde(with = "RemoteType")]`.Another alternative would be the
from
,try_from
andinto
annotations would solve this problem.RemoteType
and deriveAsExpression
etc on it.Selectable
structs, useBaseType
, and annotate it withfrom
andinto
to the newtype.Does either or both of them sound reasonable? I'm happy to try implementing it if so.
Apologies if this has been discussed already -- I searched through the tracker and couldn't find anything. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions