Crates.io | ronky |
lib.rs | ronky |
version | 0.0.16 |
source | src |
created_at | 2024-07-11 19:27:56.666506 |
updated_at | 2024-11-04 10:48:17.908777 |
description | Export a part of the Rust AST to JSON |
homepage | |
repository | https://github.com/Arthurdw/ronky |
max_upload_size | |
id | 1299928 |
size | 44,134 |
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;
}