Crates.io | struct_to_string |
lib.rs | struct_to_string |
version | 0.2.0 |
source | src |
created_at | 2023-09-23 17:07:29.129547 |
updated_at | 2023-10-02 02:00:08.955949 |
description | A Rust proc-macro library to convert struct definitions to a string representation. An example use case would be for API documentation, and you want to present the Rust struct's for the API response on a webpage. |
homepage | |
repository | https://github.com/Houski/struct_to_string |
max_upload_size | |
id | 981358 |
size | 29,522 |
A Rust procedural macro crate for converting struct definitions into a string representation.
Useful for things like API documentation where you want to display your Rust structs on a webpage.
To further assist with applications such as API documentation, it can also convert your structs to structs/classes in other languages, such as Go, Python, TypeScript, Java, and C#.
The conversion of structs to other languages may not always be perfect for complicated structs.
Add struct_to_string
to your Cargo.toml
:
[dependencies]
struct_to_string = "0.2.0"
Add the #[derive(StructToString)]
attribute to the structs you'd like to generate string representations for:
#[derive(StructToString)]
struct MyStruct {
field1: i32,
field2: String,
}
You can then use the generated to_rust_string()
function:
let my_struct_as_string = MyStruct::to_rust_string();
Which outputs a string like:
"struct MyStruct {
field1: i32,
field2: String,
}"
You can also convert your structs to structs/class strings in other languages (useful for API documentation):
let my_struct_as_typescript_string = MyStruct::to_typescript_string();
Which outputs a string like:
"interface MyStruct {
field1: number;
field2: string;
}"
The languages that this crate can convert Rust structs can be converted to are:
Though conversion may not always be perfect for complicated structs.
MIT