Giter VIP home page Giter VIP logo

Comments (4)

Kobzol avatar Kobzol commented on August 15, 2024

Hi! I'm not sure what exactly do you mean. The code that you have posted seems to work, and expands to this:

#[inline(always)]
pub fn leading_ones(&self) -> u32 {
    match self {
        WeakRenderObject::RenderBox(o) => o,
        WeakRenderObject::RenderSliver(o) => o,
        WeakRenderObject::RenderView(o) => o,
    }.leading_ones()
}

Is there something problematic with this?

from rust-delegate.

gfreezy avatar gfreezy commented on August 15, 2024
pub enum WeakRenderObject {
    RenderBox(WeakRenderBox),
    RenderSliver(WeakRenderSliver),
    RenderView(WeakRenderView),
}

struct WeakRenderBox;
struct WeakRenderSliver;
struct WeakRenderView;

WeakRenderBox WeakRenderSliver WeakRenderView are of different types. The match expr returns different types, thus compiles error.

from rust-delegate.

Kobzol avatar Kobzol commented on August 15, 2024

I see. I'm not sure what could be the ideal way to enable this use-case though 🤔 In theory, there could be some placeholder value in the target expression and the delegation macro would replace that placeholder, like this:

impl WeakRenderObject {
    delegate::delegate!(to match self {
        WeakRenderObject::RenderBox(o) => o.$delegate,
        WeakRenderObject::RenderSliver(o) => o.$delegate,
        WeakRenderObject::RenderView(o) => o.$delegate,
    } {
        pub fn is_alive(&self) -> bool;
    });
}

but I'm not sure if I can parse the code well enough so that I can find all of the placeholders. I'll try.

from rust-delegate.

Kobzol avatar Kobzol commented on August 15, 2024

Published v0.8.0 with this feature. Thank you very much!

from rust-delegate.

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.