Skip to content

Support wrapping of Preset::Provider inside cgp_preset! macro#103

Merged
soareschen merged 8 commits intomainfrom
wrap-provider
Jun 1, 2025
Merged

Support wrapping of Preset::Provider inside cgp_preset! macro#103
soareschen merged 8 commits intomainfrom
wrap-provider

Conversation

@soareschen
Copy link
Collaborator

@soareschen soareschen commented Jun 1, 2025

Summary

This PR enables the user to specify a #[wrap_provider] attribute in the cgp_preset! macro, to wrap the Preset::Provider type around the wrapper type.

Motivation

CGP presets can be used not just for wiring CGP components, but also to define extensible mappings to be used for generic dispatch through the UseDelegate pattern.

Without the provider wrapping, it becomes tedious to extend the non-provider mapping across multiple levels of preset inheritance. This is because the values in the maps are still expected to implement the provider trait, but the non-wrapped mapping type does not implement the provider trait.

With the wrapper, the Preset::Provider type would implement the expected provider trait through the wrapper, making it a valid delegation target when a child preset inherits from it.

Example

Given the following preset definition:

cgp_preset! {
    #[wrap_provider(UseDelegate)]
    MyHandlerPreset {
        String: HandleString,
        u64: HandleU64,
        ...
    }
}

The macro would generate the following implementation:

pub mod MyHandlerPreset {
    ...

    pub type Provider = UseDelegate<Components>;

    delegate_components! {
        new Components {
            String: HandleString,
            u64: HandleU64,
            ...
        }
    }

    ...
}

@soareschen soareschen merged commit ceef387 into main Jun 1, 2025
5 checks passed
@soareschen soareschen deleted the wrap-provider branch June 1, 2025 20:34
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