Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to support delegation of Constructors? Fuctions returning Self and Result<Self, SomeErr>? #66

Open
Sajjon opened this issue Feb 6, 2024 · 4 comments

Comments

@Sajjon
Copy link

Sajjon commented Feb 6, 2024

Gr8 Cr8! I would love to be able to forward all constructors as well! Do you think it would be possible?

@Kobzol
Copy link
Owner

Kobzol commented Feb 6, 2024

Hi, could you please send a code example, so that I can better understand the use-case? Thanks!

@Sajjon
Copy link
Author

Sajjon commented Feb 7, 2024

Hey! Basically every non trivial NewType or type which otherwise wraps another type, and where Id prefer to not have to instantiate the inner type and call into() on it. Being able to delegate a lot of constructors would be awesome!

@Sajjon
Copy link
Author

Sajjon commented Feb 7, 2024

Eg the Hex32Bytes structure holding an inner BagOfBytes, would be nice ti delegate the TryFrom and From impl:

https://github.com/Sajjon/RadixWalletKit/blob/develop/profile/src/wallet_kit_common/types/hex_32bytes.rs#L79

@Kobzol
Copy link
Owner

Kobzol commented Feb 7, 2024

With rust-delegate, you can't currently delegate trait implementations, due to limitations of the Rust introspection system. You could do something like this (if it were implemented):

delegate_trait! { TryFrom, Hex32Bytes, Vec<u8>>, CommonError }

but I'm not sure if that's so much better than the hand-written impl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants