Crates.io | syn_builder |
lib.rs | syn_builder |
version | 0.2.0 |
source | src |
created_at | 2023-07-16 13:17:56.706181 |
updated_at | 2023-09-21 21:40:52.837318 |
description | Builder functions for `syn` structures and enums to ease the generation of Rust code. |
homepage | |
repository | https://github.com/andrewlowndes/syn_builder |
max_upload_size | |
id | 917756 |
size | 138,449 |
Builder functions for syn
structures and enums to ease the generation of Rust code.
Note: only syn structures are creating using the builder methods - there no intermediate structs to manage.
[dependencies]
syn_builder = "0.2.0"
use proc_macro2::TokenStream;
use quote::ToTokens;
use syn_builder::*;
fn main() {
//generate code using the builder api
let code = item_enum("my_enum").variants([
variant("A").fields(
fields_unamed([field(type_path("A")), field(type_path("B"))]),
),
variant("B"),
variant("C").fields(
fields_named([
field(type_path("A")).ident("other"),
field(type_path("B")).ident("one"),
]),
),
]);
let mut token_stream = TokenStream::new();
code.to_tokens(&mut token_stream);
println!("{token_stream}");
}