#ast #json #exporter #rust

ronky

Export a part of the Rust AST to JSON

37 releases

new 0.0.35 Mar 10, 2025
0.0.32 Feb 24, 2025
0.0.23 Dec 23, 2024
0.0.20 Nov 27, 2024
0.0.1-a Jul 30, 2024

#1016 in Development tools

Download history 150/week @ 2024-11-17 264/week @ 2024-11-24 162/week @ 2024-12-01 17/week @ 2024-12-08 4/week @ 2024-12-15 236/week @ 2024-12-22 8/week @ 2024-12-29 224/week @ 2025-01-05 299/week @ 2025-01-12 134/week @ 2025-01-19 1/week @ 2025-01-26 197/week @ 2025-02-02 116/week @ 2025-02-09 39/week @ 2025-02-16 122/week @ 2025-02-23 141/week @ 2025-03-02

432 downloads per month

GPL-3.0-or-later

180KB

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

Crates.io Version

Example

There is still a lot 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 (any supported language, or create your own):

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

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

In memory of Ronky

In loving memory of my dear cat Ronky, named for his unique habit of spinning with a loud sound (to "ronk" in Dutch). Ronky lived to the age of 14 and bravely endured acromegaly. This condition resulted in the abnormal growth of his tissues and bones.

He passed away peacefully, surrounded by those who loved him. He will be deeply missed.

Beautiful picture of Ronky

Photo by Startshot

Dependencies

~0.6–1.5MB
~33K SLoC