-
I stumbled upon this crate and I think it would be nice to have this written down somewhere. I think the list should simplify choosing between the crates & better understand the aim of this crate. In particular, in discussions about rust delegate rfc's I found delegate and ambassador. So, the question is: what are the features that are unique to this crate? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I discovered one use case this crate excels at. Apparently, other crates cannot elegantly delegate associated methods to some other type. For example, the following trait delegate implementations benefit from trait SomeTrait {
fn foo() -> i32;
fn baz();
}
So, portrait can solve such use case easily: struct BaseCase;
impl SomeTrait for BaseCase {
fn foo() -> i32 { 123 }
fn baz() {
println!("Hello, World!");
}
}
struct Wrapper<T: SomeTrait>(PhantomData<T>);
#[portrait::fill(portrait::delegate(T))]
impl<T: SomeTrait> SomeTrait for Wrapper<T> { } Thanks for making this crate; now my inner perfectionist is happy 🎉 |
Beta Was this translation helpful? Give feedback.
-
portrait is actually a framework for exposing trait body to proc macros, which includes other fillers like default and log. I added delegate simply because it happens to fit in the framework as well; didn't really do research on other delegation crates in the ecosystem. But much thanks for the comparison! |
Beta Was this translation helpful? Give feedback.
I discovered one use case this crate excels at. Apparently, other crates cannot elegantly delegate associated methods to some other type. For example, the following trait delegate implementations benefit from
portrait
:So, portrait can solve such use case easily: