Urban-Analytics-Technology-Platform / popgetter-cli

A rust library and CLI for accessing popgetter data
0 stars 0 forks source link

Explore ways to generate rust code from pydantic metadata model #1

Closed stuartlynn closed 2 months ago

stuartlynn commented 2 months ago

We have a defined metadata model in popgetter that defines what metrics are available for which countries. We need to mirror that structure in rust. We want to do this using a macro based solution.

One potential solution is to

  1. Export json schema from pydantic : https://docs.pydantic.dev/latest/concepts/json_schema/
  2. use https://github.com/oxidecomputer/typify to generate rust code.

Question : Do we want to use the CLI in typify to generate the types or use the macro?

yongrenjie commented 2 months ago

Question : Do we want to use the CLI in typify to generate the types or use the macro?

The macro's probably cleaner because that avoids an extra step that we have to run before the library can be used.

To compile the library, the type info has to be present at compile time, so in both cases we still have to commit it to the repository (with the macro, we need to commit the JSON; with cargo typify we need to commit the Rust output) — unfortunately neither approach lets us dynamically generate the type-level info from e.g. an internet source which would let us avoid committing it into the repo

stuartlynn commented 2 months ago

We might be able to.do that as part of a build.rs step? Or just as a GitHub build action.

stuartlynn commented 2 months ago

There are still some questions here about versioning the spec (and exactly what the spec should look like ) but #10 mostly covers the basics.