Giter VIP home page Giter VIP logo

Comments (1)

obmarg avatar obmarg commented on September 27, 2024

Hi @alefbragin - thanks for the feature request.

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.

from cynic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.