Skip to content

Redesign cgp_type to work as attribute macro#68

Merged
soareschen merged 7 commits intomainfrom
cgp-type-redesign
Feb 16, 2025
Merged

Redesign cgp_type to work as attribute macro#68
soareschen merged 7 commits intomainfrom
cgp-type-redesign

Conversation

@soareschen
Copy link
Collaborator

@soareschen soareschen commented Feb 16, 2025

This PR redesigns the cgp_type macro to make it an attribute macro following the same syntax as cgp_component. This is to allow for more complex CGP type components to be defined using the same macro, which may include generic parameters or super traits on the consumer trait.

The main change is as follows:

Before:

cgp_type!( Name: Display );

After:

#[cgp_type]
pub trait HasNameType {
  type Name: Display;
}

This PR also changes the implicit naming convention for the provider and component names. If no parameter is specified, cgp_type would use {Type}TypeProvider as the provider name, and {Type}TypeProviderComponent as the component name. So the above definition can also be made explicit with:

#[cgp_type {
    name: NameTypeProviderComponent,
    provider: NameTypeProvider,
}]
pub trait HasNameType {
  type Name: Display;
}

@soareschen soareschen merged commit 6a0bb4d into main Feb 16, 2025
5 checks passed
@soareschen soareschen deleted the cgp-type-redesign branch February 16, 2025 18:40
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