Giter Club home page Giter Club logo

Comments (3)

Kobzol avatar Kobzol commented on June 15, 2024 1

Hi! :) This is actually pretty easy to implement and it would enable delegating wrappers, which is nice. Although writing arbitrary expressions/method calls (we can also allow calling global functions) inside a macro feels a bit unintuitive to me.

Here's what I don't like:

  • When you make an error in the call expression, you get an error message pointing to the expression. However if the error occurs in the generated delegation method, it will still be matched back to the call expression, so it is hard to find out what is wrong. Try to use the Mutex example with a delegated method that takes self by value to see what I mean. I'll check if this can be fixed.
  • The call expression looks like it is invoked only once, but it is actually copy pasted inside each delegated method and it will be called everytime the delegated method is invoked. Therefore the expression should ideally not have any side effects. Though in Rust it's relatively safe because side effects are kind of difficult to create with such a function call, so maybe it's not a big deal.

I suppose that if it will be optional, there's not much harm to be done. I implemented a prototype of it here: https://github.com/chancancode/rust-delegate/tree/expr. Please test it out if it works for your use cases.

from rust-delegate.

MingweiSamuel avatar MingweiSamuel commented on June 15, 2024

I confirmed that this works for my (relatively simple) use case. I definitely understand the concerns though. Also thanks for the super fast response!

from rust-delegate.

Kobzol avatar Kobzol commented on June 15, 2024

Closed by #15.

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.