#ast #json #exporter #rust

ronky

Export a part of the Rust AST to JSON

9 releases

new 0.0.7 Sep 2, 2024
0.0.6 Sep 2, 2024
0.0.6-a Aug 19, 2024
0.0.1-a Jul 30, 2024

#776 in Development tools

Download history 80/week @ 2024-07-06 13/week @ 2024-07-13 115/week @ 2024-07-27 118/week @ 2024-08-03 193/week @ 2024-08-10 234/week @ 2024-08-17 12/week @ 2024-08-24 283/week @ 2024-08-31

730 downloads per month

GPL-3.0-or-later

19KB

Ronky - A simple way to export Rust definitions to other languages

Example

There is still alot of work to be done, but here is a simple example of what I have in mind.

The following code and it's output:

#[derive(Export)]
struct Human {
    name: String,
    age: u32,
    friends: Vec<Human>,
    pets: Vec<Pet>,
}

#[derive(Export)]
struct Pet {
    name: String,
    species: String,
}

Which results in the following JSON:

{
  "types": [
    {
      "name": "Human",
      "fields": [
        {
          "name": "name",
          "type": "String"
        },
        {
          "name": "age",
          "type": "u32"
        },
        {
          "name": "friends",
          "type": "list"
          "of": ["Human"],
        },
        {
          "name": "pets",
          "type": "list"
          "of": ["Pet"],
        }
      ]
    },
    {
      "name": "Pet",
      "fields": [
        {
          "name": "name",
          "type": "String"
        },
        {
          "name": "species",
          "type": "String"
        }
      ]
    }
  ]
}

That can then be converted to the following typescript (or any supported language):

interface Human {
  name: string;
  age: number;
  friends: Human[];
  pets: Pet[];
}

interface Pet {
  name: string;
  species: string;
}

Dependencies

~0.7–1.6MB
~34K SLoC