Skip to content

Support derivation of UseDelegate inside #[cgp_component]#106

Merged
soareschen merged 12 commits intomainfrom
derive-use-delegate
Jun 2, 2025
Merged

Support derivation of UseDelegate inside #[cgp_component]#106
soareschen merged 12 commits intomainfrom
derive-use-delegate

Conversation

@soareschen
Copy link
Collaborator

@soareschen soareschen commented Jun 2, 2025

Summary

This PR introduces a new derive_delegate field for the #[cgp_component] family macros, allowing automated implementation of UseDelegate for CGP components.

Example

The updated ErrorRaiser component is defined as follows:

#[cgp_component {
    provider: ErrorRaiser,
    derive_delegate: UseDelegate<SourceError>,
}]
pub trait CanRaiseError<SourceError>: HasErrorType {
    fn raise_error(error: SourceError) -> Self::Error;
}

which would derive the following UseDelegate implementation, which previously had to be implemented manually:

#[cgp_provider(ErrorRaiserComponent)]
impl<Context, SourceError, Components, Delegate> ErrorRaiser<Context, SourceError>
    for UseDelegate<Components>
where
    Context: HasErrorType,
    Components: DelegateComponent<SourceError, Delegate = Delegate>,
    Delegate: ErrorRaiser<Context, SourceError>,
{
    fn raise_error(e: SourceError) -> Context::Error {
        Delegate::raise_error(e)
    }
}

@soareschen soareschen merged commit 147d5e6 into main Jun 2, 2025
5 checks passed
@soareschen soareschen deleted the derive-use-delegate branch June 2, 2025 12:18
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

Successfully merging this pull request may close these issues.

1 participant