Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a derive macro for CustomState #174

Open
Saethox opened this issue Jun 5, 2023 · 1 comment
Open

Add a derive macro for CustomState #174

Saethox opened this issue Jun 5, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@Saethox
Copy link
Collaborator

Saethox commented Jun 5, 2023

#[derive(CustomState)]
pub struct MyCustomState(f64);

should implement CustomState and better_any::Tid (or an equivalent). It should also handle a single lifetime and multiple generics correctly.

@Saethox Saethox added the enhancement New feature or request label Jun 5, 2023
@Saethox
Copy link
Collaborator Author

Saethox commented Aug 20, 2023

A shortcut for exposing Component parameters would also be handy. Maybe something like this is possible with some proc-macro magic:

Annotate component fields with some attribute, which generates a SomeComponentMutationRate(f64) custom state struct:

#[derive(ExposedParameter)]
pub struct SomeComponent {
    #[expose(rename = "mutation_rate")]
    pub f64: rm,
}

The struct can then be referred to in Component methods using some Param![] macro:

fn execute(problem: &P, state: &mut State<P>) -> ExecResult<()> {
    let mutation_rate = state.get_value::<Param![SomeComponent::mutation_rate]>();
    ...
}

Maybe it's even possible to use Param![Self::mutation_rate] in SomeComponent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant