Introduce #[cgp_impl] to simplify provider trait implementation
#174
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a new
#[cgp_impl]macro that replaces the#[cgp_provider]macro and provides much better ergonomics for implementing provider traits in CGP.In essence,
#[cgp_impl]allows you to write a provider trait implementation as if it is a blanket implementation for the consumer trait. With this, the implementation of CGP providers become as intuitive as just implementing regular Rust traits.Example
Consider the following example trait:
With
#[cgp_impl], you can now implement a provider such as follows:Compared to before, you would have to implement the provider using
#[cgp_provider]as follows:As we can see, the ergonomic for
#[cgp_impl]is much closer to vanilla Rust trait implementation.Behind the scene,
#[cgp_impl]desugars the provider trait implementation to the same as how you would manually write it using#[cgp_provider]. So understanding of provider traits is still necessary, especially during debugging.