-
-
Notifications
You must be signed in to change notification settings - Fork 514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to implement From<Option<T>> for Value where T is my custom value? #107
Comments
They're defined in https://github.com/SeaQL/sea-query/blob/cfae4eab32fcd1a87103cffcf8760315f404656f/src/value.rs#L173 So you think impl<T: Into<Value>> From<Option<T>> for Value instead of impl From<Option<$type>> for Value { would help? |
Yes, I've gone there only after opening the issue, and saw how you implemented Value... To be honest, the same approach has been used by, for example, serde_json::Value, where variants aren't Option, and there is a Null variant to express the null value without knowing the type of the field. I don't know if your approach has been forced by some requirements, but it's kind of less flexible. |
It was only recently being removed SeaQL/sea-query#107
…________________________________
寄件者: Marco Napetti ***@***.***>
寄件日期: Thursday, August 26, 2021 12:20:07 AM
收件者: SeaQL/sea-orm ***@***.***>
副本: Chris Tsang ***@***.***>; Comment ***@***.***>
主旨: Re: [SeaQL/sea-orm] How to implement From<Option<T>> for Value where T is my custom value? (#107)
Yes, I've gone there only after opening the issue, and saw how you implemented Value...
This way you're locked by type, because for example bool values goes into Value::Bool and I can't see a generic to reconduce a None:: into the righ Value variant.
A solution could be introduce Value::Null, this way the null value would be unique instead of typed.
To be honest, the same approach has been used by, for example, by serde_json::Value, where variants aren't Option, and there is a Null variant to express the null value without knowing the type of the field.
I don't know if your approach has been forced by some requirements, but it's kind of less flexible.
How do you see it?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<https://apac01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.luolix.top%2FSeaQL%2Fsea-orm%2Fissues%2F107%23issuecomment-905682282&data=04%7C01%7C%7C2731f5a080bb477b2f4e08d967e4342b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637655052097814281%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=%2FvimfWrYU6oXIpHClZfnlwiz67xR7%2BEv0qzs7VFCMqM%3D&reserved=0>, or unsubscribe<https://apac01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.luolix.top%2Fnotifications%2Funsubscribe-auth%2FAANTHCCDJTWB6HPU5ZWH4OLT6UJ3PANCNFSM5CZNGXVA&data=04%7C01%7C%7C2731f5a080bb477b2f4e08d967e4342b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637655052097824235%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=VnKb7yukgsCqLZg%2F6eVB%2FLJDuXazlfIoCddErm9%2F3WQ%3D&reserved=0>.
|
I see...
Well, this is a problem...
A solution could be a Trait that adds a method like `fn null() -> Value`
that returns the correct variant of Value containing None, and requiring
that trait in the generic impl
Il mer 25 ago 2021, 18:42 Chris Tsang ***@***.***> ha scritto:
… It was only recently being removed
SeaQL/sea-query#107
________________________________
寄件者: Marco Napetti ***@***.***>
寄件日期: Thursday, August 26, 2021 12:20:07 AM
收件者: SeaQL/sea-orm ***@***.***>
副本: Chris Tsang ***@***.***>; Comment ***@***.***>
主旨: Re: [SeaQL/sea-orm] How to implement From<Option<T>> for Value where T
is my custom value? (#107)
Yes, I've gone there only after opening the issue, and saw how you
implemented Value...
This way you're locked by type, because for example bool values goes into
Value::Bool and I can't see a generic to reconduce a None:: into the righ
Value variant.
A solution could be introduce Value::Null, this way the null value would
be unique instead of typed.
To be honest, the same approach has been used by, for example, by
serde_json::Value, where variants aren't Option, and there is a Null
variant to express the null value without knowing the type of the field.
I don't know if your approach has been forced by some requirements, but
it's kind of less flexible.
How do you see it?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<
https://apac01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.luolix.top%2FSeaQL%2Fsea-orm%2Fissues%2F107%23issuecomment-905682282&data=04%7C01%7C%7C2731f5a080bb477b2f4e08d967e4342b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637655052097814281%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=%2FvimfWrYU6oXIpHClZfnlwiz67xR7%2BEv0qzs7VFCMqM%3D&reserved=0>,
or unsubscribe<
https://apac01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.luolix.top%2Fnotifications%2Funsubscribe-auth%2FAANTHCCDJTWB6HPU5ZWH4OLT6UJ3PANCNFSM5CZNGXVA&data=04%7C01%7C%7C2731f5a080bb477b2f4e08d967e4342b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637655052097824235%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=VnKb7yukgsCqLZg%2F6eVB%2FLJDuXazlfIoCddErm9%2F3WQ%3D&reserved=0>.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#107 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABZXINLMHNWI4B6MZH74ZSLT6UMNRANCNFSM5CZNGXVA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
.
|
Sounds viable although I am not 100% sure Ferris wouldn’t complain.
|
Tomorrow I can try to arrange a PR if you need it
Il mer 25 ago 2021, 19:16 Chris Tsang ***@***.***> ha scritto:
… Sounds viable although I am not 100% sure Ferris wouldn’t complain.
________________________________
寄件者: Marco Napetti ***@***.***>
寄件日期: Thursday, August 26, 2021 12:48:53 AM
收件者: SeaQL/sea-orm ***@***.***>
副本: Chris Tsang ***@***.***>; Comment ***@***.***>
主旨: Re: [SeaQL/sea-orm] How to implement From<Option<T>> for Value where T
is my custom value? (#107)
I see...
Well, this is a problem...
A solution could be a Trait that adds a method like `fn null() -> Value`
that returns the correct variant of Value containing None, and requiring
that trait in the generic impl
Il mer 25 ago 2021, 18:42 Chris Tsang ***@***.***> ha scritto:
> It was only recently being removed
> SeaQL/sea-query#107
> ________________________________
> 寄件者: Marco Napetti ***@***.***>
> 寄件日期: Thursday, August 26, 2021 12:20:07 AM
> 收件者: SeaQL/sea-orm ***@***.***>
> 副本: Chris Tsang ***@***.***>; Comment ***@***.***>
> 主旨: Re: [SeaQL/sea-orm] How to implement From<Option<T>> for Value where
T
> is my custom value? (#107)
>
>
> Yes, I've gone there only after opening the issue, and saw how you
> implemented Value...
> This way you're locked by type, because for example bool values goes
into
> Value::Bool and I can't see a generic to reconduce a None:: into the
righ
> Value variant.
> A solution could be introduce Value::Null, this way the null value would
> be unique instead of typed.
>
> To be honest, the same approach has been used by, for example, by
> serde_json::Value, where variants aren't Option, and there is a Null
> variant to express the null value without knowing the type of the field.
>
> I don't know if your approach has been forced by some requirements, but
> it's kind of less flexible.
> How do you see it?
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub<
>
https://apac01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.luolix.top%2FSeaQL%2Fsea-orm%2Fissues%2F107%23issuecomment-905682282&data=04%7C01%7C%7C2731f5a080bb477b2f4e08d967e4342b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637655052097814281%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=%2FvimfWrYU6oXIpHClZfnlwiz67xR7%2BEv0qzs7VFCMqM%3D&reserved=0>,
> or unsubscribe<
>
https://apac01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.luolix.top%2Fnotifications%2Funsubscribe-auth%2FAANTHCCDJTWB6HPU5ZWH4OLT6UJ3PANCNFSM5CZNGXVA&data=04%7C01%7C%7C2731f5a080bb477b2f4e08d967e4342b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637655052097824235%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=VnKb7yukgsCqLZg%2F6eVB%2FLJDuXazlfIoCddErm9%2F3WQ%3D&reserved=0>.
>
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#107 (comment)>,
or
> unsubscribe
> <
https://github.com/notifications/unsubscribe-auth/ABZXINLMHNWI4B6MZH74ZSLT6UMNRANCNFSM5CZNGXVA>
> .
> Triage notifications on the go with GitHub Mobile for iOS
> <
https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
> or Android
> <
https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
> .
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<
https://apac01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.luolix.top%2FSeaQL%2Fsea-orm%2Fissues%2F107%23issuecomment-905704069&data=04%7C01%7C%7C22bbcf5b515f481d9efb08d967e83937%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637655069354537936%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=%2BXpa%2F3IVhthlSV9y%2FZCrUWfXKS5wgKFHDN7fPch8ozs%3D&reserved=0>,
or unsubscribe<
https://apac01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.luolix.top%2Fnotifications%2Funsubscribe-auth%2FAANTHCFQGVGEYAJAB6Z4GUTT6UNHLANCNFSM5CZNGXVA&data=04%7C01%7C%7C22bbcf5b515f481d9efb08d967e83937%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637655069354547894%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=1IybVfXaeOLXqHkOZKx5d63opmTupCDUdjmdU%2B1kZVc%3D&reserved=0>.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#107 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABZXINPLFIMZK2BX3VJI5ILT6UQQBANCNFSM5CZNGXVA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
.
|
Definitely welcome!
|
With #108 merged, is there still any other blocker? |
No, on this topic there are no blockers |
Let's say I have a field in my table, something like
status can have those values: A (active), D (deleted), Q (queued), E (executed).
I want to map the field to a Rust enum, I can easily do:
and everything works fine.
But if my status is, instead
In my Model I would have to use Option< Status>, and I cant impl From< Option< Status>> for Value, because neither Option or Value comes from my crate.
Maybe you could solve removing every impl From< Option< Something>> for Value and replacing it with a simple impl< T: Into< Value>> From< Option< T>> for Value, I don't know if there would be conflicts, but this way you unlock a lot of custom types potentials
The text was updated successfully, but these errors were encountered: