You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is the impl_scalar! macro. It's really convenient for external scalar types:
use chrono::{DateTime,Utc};impl_scalar!(DateTime<Utc>, schema::DateTime);
My case. My current project has several bins and shared libs. Libs have commonly used enums, libs isn't aware about cynic and schema, but enums are the same. It will be great to have something like impl_enum!(some_lib::SomeEnum, schema::SomeEnum). This approach lacks variant rename feature though , and needs some additions for these cases.
The text was updated successfully, but these errors were encountered:
Unfortunately doing this for enums would be somewhere between difficult and impossible. Enums are more complicated than scalars. For scalars cynic simply needs to know the type, but for enums we need to care about all the variants, possible fallbacks, renames and maybe other things I'm forgetting about.
Given the schema and some type names it would probably be possible to generate a cynic::Enum impl - but it'd have to make some assumptions about the shape of your actual enum. And if that impl was wrong in any way the compiler errors probably wouldn't be that nice - there's just not enough info in impl_enum!("my-schema", MyEnum, schema::MyEnum) that we could use to attach errors to.
And the final problem is the orphan rule - impl_scalar uses some tricks (specifically this generic parameter on IsScalar) to work around the orphan rule - usually you wouldn't be able to implement a 3rd party trait on a 3rd party type like it does. The Enum trait does not have an equivalent parameter, so the orphan rule starts to apply again.
The generic parameter on IsScalar adds a bit of annoying complexity to cynic. I think it's worthwhile for scalars, because by their nature they tend to be defined in different crates. But I'm not so sure for enums - particularly given the limitations I outlined above.
If re-arranging your crates isn't possible or desired at the moment (which is fair enough) I'd recommend just having two enums and providing some From impls to easily convert between the two.
There might be some other way I can help cater to this use case in cynic, but I don't know what it is right now. I'll keep this issue open for now to think about it.
There is the
impl_scalar!
macro. It's really convenient for external scalar types:My case. My current project has several bins and shared libs. Libs have commonly used enums, libs isn't aware about cynic and schema, but enums are the same. It will be great to have something like
impl_enum!(some_lib::SomeEnum, schema::SomeEnum)
. This approach lacks variant rename feature though , and needs some additions for these cases.The text was updated successfully, but these errors were encountered: