Comments (3)
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.
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.
Closed by #15.
from rust-delegate.
Related Issues (20)
- New Release Please HOT 2
- Delegate target cannot come from macro expansion
- Nested proc attributes HOT 1
- Arbitrary inner field expressions HOT 2
- self as target doesn't seem to work HOT 9
- is it possible to delegate all methods? HOT 2
- 0.5.0 fails to compile
- Delegate with additional arguments
- Transfer ownership! HOT 3
- Bridging sync to async gap with delegate HOT 5
- Allow #[from] and #[into] annotations, pattern-matching or even arbitrary transformation functions for delegated arguments HOT 10
- allow #[try_from] and #[try_into] HOT 8
- Is delegating to enum in the target range HOT 4
- Compatability with async_trait HOT 2
- Just unwrap HOT 3
- Assign Return Value Of Delegated Calls To Delegated Field HOT 7
- Add attribute to the return value of all methods HOT 4
- Add support support for qualified calls HOT 6
- Delegate to Self HOT 1
- transform the return value of `Result` and `Option` type HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-delegate.