struct_to_string

Crates.iostruct_to_string
lib.rsstruct_to_string
version0.2.0
sourcesrc
created_at2023-09-23 17:07:29.129547
updated_at2023-10-02 02:00:08.955949
descriptionA 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
repositoryhttps://github.com/Houski/struct_to_string
max_upload_size
id981358
size29,522
(Houski)

documentation

README

struct_to_string

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.

Installation

Add struct_to_string to your Cargo.toml:

[dependencies]
struct_to_string = "0.2.0"

Usage

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:

  • Rust
  • Go
  • Python
  • TypeScript
  • Java
  • C#

Though conversion may not always be perfect for complicated structs.

License

MIT


Commit count: 6

cargo fmt