GithubHelp home page GithubHelp logo

Comments (3)

MarijnS95 avatar MarijnS95 commented on July 18, 2024

Hi @XAMPPRocky, I've previously explored this path and the problem is that newer derive_more does not omit duplicate impl From<>, instead requiring us to manually add #[from(ignore)].

Either:

  • We take this issue to derive_more and ask to reintroduce this behaviour;
  • Add some extra logic in the autogenerator to emit #[from(ignore)] on all types that occur more than once.

from rspirv.

XAMPPRocky avatar XAMPPRocky commented on July 18, 2024

We take this issue to derive_more and ask to reintroduce this behaviour

Well I'm not the maintainer, but I think a reasonable proposal could be adding a container level parameter for the from_derive that provides this behaviour.

#[derive(From)]
#[from(ignore_conflicting_types)]
pub enum Foo {
    Foo(u32),
    Bar(u32),
}

Add some extra logic in the autogenerator to emit #[from(ignore)] on all types that occur more than once.

I'd maybe go step further at that point and auto-generate the From impl in the crate and remove derive_more as a dependency entirely.

Another option might be to move the derive_more crate into the autogen crate, and call the derive_more::derive_from at codegen time, so that the generated code only contains the From impls and doesn't require derive_more as a dependency.

from rspirv.

MarijnS95 avatar MarijnS95 commented on July 18, 2024

@XAMPPRocky I really like the idea of calling derive_more::from_derive at regen/autogen time to get rid of the "runtime" dependency completely. The signature takes and generates a TokenStream making it really easy to plug into the current solution. However, derive_more is a proc-macro = true crate, imposing all kinds of nasty restrictions on exports.

Working around that results in:

thread 'main' panicked at 'procedural macro API is used outside of a procedural macro', library/proc_macro/src/bridge/client.rs:331:17

😞

Fixing the duplication in rspirv is a bit of a mess too as there's no comparison or hashing on TokenStreams. I can probably work the duplication check elsewhere in the code but stringifying is easiest: master...MarijnS95:derive-more

Note that I've only fixed Operand whose ::from is actively used. We should probably apply the same treatment to Decoration if used externally.

I'm more inclined to fix this upstream, given that code for that was already available upstream at some point.

from rspirv.

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.