Could remove 200 lines from this project if only we had trait delegation. Keep coming back to this as a small ergonomic improvement that would be fantastic to have eventually.
Delegation in this context means: expose a {trait, method} of some inner type. You could imagine something like this: struct MyType { inner: Vec<u8> } impl MyType { delegate get = inner.get; } MyType now has a "get" method as if it was a concrete impl.
-
-
Delegating AsyncRead to an inner type is ~25 lines of boilerplate per file. Being able to forward this would be great! Also worth noting this is different from Deref/DerefMut. Sometimes you want to forward impls "dynamically" (*cough*, Mutex). But new types are common too!
Show this threadThanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
This would be such a useful ergonomic improvement. I often find myself wanting something like this. I thiiiiiink JS has it in some recent version.
-
Afaik in JS it's usually: class Foo extends Bar {} But that's different from the Symbol mixins which are closer to Rust traits. For those there's no delegation shorthands available afaik. Close though!
End of conversation
New conversation -
-
-
This is akin to Elixir's defdelegate: https://hexdocs.pm/elixir/master/Kernel.html#defdelegate/2 … or Go's ability to compose structs and interfaces.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.