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 list of models to the generated code #11

Open
bikeshedder opened this issue Oct 18, 2024 · 0 comments
Open

Add a list of models to the generated code #11

bikeshedder opened this issue Oct 18, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@bikeshedder
Copy link
Owner

bikeshedder commented Oct 18, 2024

As of now everything is fully typed and there is no proper "list of models" available.


Originally written by @jacobsvante:

(...) I'd like to request is adding an enum containing all the model names, and a way to go from those to the actual models. I had the need for this when creating a CLI for quickly firing off requests. As you can see in my example below it's quite cumbersome as of today:

#[derive(Debug, Clone, Copy, ValueEnum)]
pub(crate) enum SunspecModel {
    M1,
    M2,
    M3,
}

impl SunspecModel {
    async fn read(
        &self,
        ctx: &mut Context,
        models: &mut Models,
    ) -> anyhow::Result<Box<dyn std::fmt::Debug>> {
        let config = sunspec::Config::default();
        match self {
            SunspecModel::M1 => Ok(Box::new(read_model(ctx, &models.m1, &config).await?)),
            SunspecModel::M2 => Ok(Box::new(read_model(ctx, &models.m2, &config).await?)),
            SunspecModel::M3 => Ok(Box::new(read_model(ctx, &models.m3, &config).await?)),
        }
    }
}

Originally posted by @jacobsvante in #9 (comment)

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